parseU10Int vs. parseInt(,10) (v2)

Revision 2 of this benchmark created by Devyn Cairns on


Preparation HTML

<script>
  var num = "2092109302";
  
  function parseU10Int(str) {
    var n = 0,
        c;
    for (var i = 0, len = str.length; i < len; i++) {
      c = str.charCodeAt(i) - 48;
      if (c >= 0 && c <= 9) {
        n = n * 10 + c;
      } else {
        return n;
      }
    }
    return n;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
parseU10Int
parseU10Int(num);
ready
parseInt(,10)
parseInt(num, 10);
ready
parseInt (no base specified)
parseInt(num);
ready
+n
+num;
ready

Revisions

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

  • Revision 1: published by Devyn Cairns on
  • Revision 2: published by Devyn Cairns on