split/substring vs regex to parse integer from string (v9)

Revision 9 of this benchmark created on


Preparation HTML

<script>
</script>

Setup

var str = 'col15 row16';
    var strlen = str.length;
    var i=0;
    var code = 0;
    var flags = 0;
    var row = 0;
    var col = 0;
    var split;
    var arr;

Test runner

Ready to run.

Testing in
TestOps/sec
split/parse
split = str.split(' ');
col = parseInt(split[0].substr(3));
row = parseInt(split[1].substr(3));
ready
regex get
arr = str.match(/\d+/g)
col = parseInt(arr[0]);
row = parseInt(arr[1]);
ready
parse
flags = 0;
i=0;
while(i<strlen) {
    code = str.charCodeAt(i);
    if(code === 32) {
        flags = 1;
    } else if(code > 47 && code < 58) {
        if(flags === 0) {
            row = row * 10 + code - 48;
        } else {
            col = col * 10 + code - 48;
        }
    }
    i++;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.