Skip to content

Instantly share code, notes, and snippets.

@ox
Created July 16, 2013 21:56
Show Gist options
  • Save ox/6015522 to your computer and use it in GitHub Desktop.
Save ox/6015522 to your computer and use it in GitHub Desktop.
profiling of various javascript faculties
Benchmark Samples Time Per Rate
Built In
Do nothing 10,000,000 0.028s 0.003µs 357,000,000/sec
Call a function 10,000,000 0.076s 0.008µs 131,000,000/sec
Create a string 10,000,000 0.027s 0.003µs 370,000,000/sec
Create an array 10,000,000 0.131s 0.013µs 76,300,000/sec
Create a persistent array 10,000,000 0.131s 0.013µs 76,300,000/sec
Increment a number in own scope 10,000,000 0.027s 0.003µs 370,000,000/sec
Increment a number in enclosing scope 10,000,000 0.044s 0.004µs 227,000,000/sec
Get the current time 10,000,000 0.763s 0.076µs 13,100,000/sec
Native
Call into native code returning undefined 1,000,000 0.043s 0.043µs 23,200,000/sec
Call into native code returning string 1,000,000 0.130s 0.130µs 7,690,000/sec
Call into native code that calls back to JS 1,000,000 0.202s 0.202µs 4,950,000/sec
Call into native code that calls back to JS 10x 100,000 0.157s 1.570µs 636,000/sec
Error
Set up an exception frame 1,000,000 0.009s 0.009µs 111,000,000/sec
Create an error 100,000 0.703s 7.030µs 142,000/sec
Create and throw an error 100,000 0.710s 7.100µs 140,000/sec
Get a stack trace 1,000 0.130s 130.000µs 7,690/sec
Array
Array.shift() out of array[10] 1,000,000 0.135s 0.135µs 7,400,000/sec
Array.shift() out of array[100] 1,000,000 0.124s 0.124µs 8,060,000/sec
Array.shift() out of array[1000] 1,000,000 0.124s 0.124µs 8,060,000/sec
Array.shift() out of array[10000] 1,000,000 0.122s 0.122µs 8,190,000/sec
Array.push() onto array[10] 1,000,000 0.102s 0.102µs 9,800,000/sec
Array.push() onto array[100] 1,000,000 0.076s 0.076µs 13,100,000/sec
Array.push() onto array[1000] 1,000,000 0.097s 0.097µs 10,300,000/sec
Array.push() onto array[10000] 1,000,000 0.087s 0.087µs 11,400,000/sec
Array.pop() off of array[10] 1,000,000 0.083s 0.083µs 12,000,000/sec
Array.pop() off of array[100] 1,000,000 0.081s 0.081µs 12,300,000/sec
Array.pop() off of array[1000] 1,000,000 0.068s 0.068µs 14,700,000/sec
Array.pop() off of array[10000] 1,000,000 0.087s 0.087µs 11,400,000/sec
Create Array[10] using Array.push 1,000,000 0.126s 0.126µs 7,930,000/sec
Create Array[10] using Array.new 1,000,000 0.024s 0.024µs 41,600,000/sec
Create Array[100] using Array.push 100,000 0.070s 0.700µs 1,420,000/sec
Create Array[100] using Array.new 100,000 0.011s 0.110µs 9,090,000/sec
Create Array[1000] using Array.push 10,000 0.065s 6.500µs 153,000/sec
Create Array[1000] using Array.new 10,000 0.011s 1.100µs 909,000/sec
Create Array[10000] using Array.push 1,000 0.065s 65.000µs 15,300/sec
Create Array[10000] using Array.new 1,000 0.010s 10.000µs 100,000/sec
Object
Create a Short Lived Object in place 10,000,000 0.081s 0.008µs 123,000,000/sec
Create a Short Lived Object using new Object 10,000,000 0.432s 0.043µs 23,100,000/sec
Create a Short Lived Object using new Function 10,000,000 0.094s 0.009µs 106,000,000/sec
Create a Long Lived Object (100K) 100,000 0.000s 0.000µs 0/sec
Create a Long Lived Object (1M) 1,000,000 0.075s 0.075µs 13,300,000/sec
Create a Long Lived Object (10M) 10,000,000 1.035s 0.103µs 9,660,000/sec
Increment an object's member defined in prototype 10,000,000 0.093s 0.009µs 107,000,000/sec
Assign to an object's member defined in prototype 10,000,000 0.084s 0.008µs 119,000,000/sec
Increment an object's member defined in prototype statically 10,000,000 0.121s 0.012µs 82,600,000/sec
Assign to an object's member defined in prototype statically 10,000,000 0.108s 0.011µs 92,500,000/sec
Increment an object's member defined locally 10,000,000 0.089s 0.009µs 112,000,000/sec
Assign to an object's member defined locally 10,000,000 0.095s 0.009µs 105,000,000/sec
Array
Array.shift() out of array[10] 1,000,000 0.122s 0.122µs 8,190,000/sec
Array.shift() out of array[100] 1,000,000 0.126s 0.126µs 7,930,000/sec
Array.shift() out of array[1000] 1,000,000 0.131s 0.131µs 7,630,000/sec
Array.shift() out of array[10000] 1,000,000 0.129s 0.129µs 7,750,000/sec
Array.push() onto array[10] 1,000,000 0.080s 0.080µs 12,500,000/sec
Array.push() onto array[100] 1,000,000 0.078s 0.078µs 12,800,000/sec
Array.push() onto array[1000] 1,000,000 0.080s 0.080µs 12,500,000/sec
Array.push() onto array[10000] 1,000,000 0.072s 0.072µs 13,800,000/sec
Array.pop() off of array[10] 1,000,000 0.076s 0.076µs 13,100,000/sec
Array.pop() off of array[100] 1,000,000 0.086s 0.086µs 11,600,000/sec
Array.pop() off of array[1000] 1,000,000 0.079s 0.079µs 12,600,000/sec
Array.pop() off of array[10000] 1,000,000 0.080s 0.080µs 12,500,000/sec
Create Array[10] using Array.push 1,000,000 0.129s 0.129µs 7,750,000/sec
Create Array[10] using Array.new 1,000,000 0.024s 0.024µs 41,600,000/sec
Create Array[100] using Array.push 100,000 0.071s 0.710µs 1,400,000/sec
Create Array[100] using Array.new 100,000 0.010s 0.100µs 10,000,000/sec
Create Array[1000] using Array.push 10,000 0.064s 6.400µs 156,000/sec
Create Array[1000] using Array.new 10,000 0.010s 1.000µs 1,000,000/sec
Create Array[10000] using Array.push 1,000 0.068s 68.000µs 14,700/sec
Create Array[10000] using Array.new 1,000 0.009s 9.000µs 111,000/sec
String Concatenation
Concatenate two strings using + 10,000,000 0.212s 0.021µs 47,100,000/sec
Concatenate two strings using += 10,000,000 0.265s 0.026µs 37,700,000/sec
String Concatenation as a function of size
Concatenate strings of size 10 1,000,000 0.066s 0.066µs 15,100,000/sec
Concatenate strings of size 100 1,000,000 0.066s 0.066µs 15,100,000/sec
Concatenate strings of size 1000 1,000,000 0.068s 0.068µs 14,700,000/sec
Concatenate strings of size 10000 1,000,000 0.069s 0.069µs 14,400,000/sec
Concatenate strings of size 100000 1,000,000 0.088s 0.088µs 11,300,000/sec
Concatenate strings of size 1000000 1,000,000 0.077s 0.077µs 12,900,000/sec
Concatenate strings of size 10000000 1,000,000 0.119s 0.119µs 8,400,000/sec
Q
Create a promise 10,000 0.030s 3.000µs 333,000/sec
Create a promise & resolve it 10,000 0.078s 7.800µs 128,000/sec
Create a 2 deep promise chain & resolve it 10,000 0.222s 22.200µs 45,000/sec
Kew
Create a promise 1,000,000 0.030s 0.030µs 33,300,000/sec
Create a promise & resolve it 100,000 0.012s 0.120µs 8,330,000/sec
Create a 2 deep promise chain & resolve it 10,000 0.003s 0.300µs 3,330,000/sec
Call 10 functions in order 1,000,000 0.116s 0.116µs 8,620,000/sec
Call 5 functions via promise chain 10,000 0.415s 41.500µs 24,000/sec
Call 10 functions via promise chain 10,000 0.122s 12.200µs 81,900/sec
Call 15 functions via promise chain 10,000 0.374s 37.400µs 26,700/sec
Call 20 functions via promise chain 10,000 0.438s 43.800µs 22,800/sec
Call 25 functions via promise chain 10,000 0.489s 48.900µs 20,400/sec
Call 30 functions via promise chain 10,000 0.541s 54.100µs 18,400/sec
Call 35 functions via promise chain 10,000 0.593s 59.300µs 16,800/sec
Call 40 functions via promise chain 10,000 0.646s 64.600µs 15,400/sec
Call 45 functions via promise chain 10,000 0.709s 70.900µs 14,100/sec
Call 10 functions via promise stack 10,000 0.184s 18.400µs 54,300/sec
Comparisons
Comparing equal two strings with == 10,000,000 0.018s 0.002µs 555,000,000/sec
Comparing equal two strings with === 10,000,000 0.016s 0.002µs 625,000,000/sec
Comparing unequal two strings with == 10,000,000 0.023s 0.002µs 434,000,000/sec
Comparing unequal two strings with === 10,000,000 0.017s 0.002µs 588,000,000/sec
InstanceOf Builtins
Testing if an Object is an Object 10,000,000 0.019s 0.002µs 526,000,000/sec
Testing if an Object is an Array 10,000,000 0.019s 0.002µs 526,000,000/sec
Testing if an Array is an Array 10,000,000 0.017s 0.002µs 588,000,000/sec
Testing if an Array is an Object 10,000,000 0.017s 0.002µs 588,000,000/sec
InstanceOf Classes
Testing if a Foo is a Foo 10,000,000 0.044s 0.004µs 227,000,000/sec
Testing if a Foo is a Object 10,000,000 0.021s 0.002µs 476,000,000/sec
Testing if an Object is a Foo 10,000,000 0.046s 0.005µs 217,000,000/sec
Testing if a Bar is a Foo 10,000,000 0.033s 0.003µs 303,000,000/sec
Testing if a string is a Foo 10,000,000 0.189s 0.019µs 52,900,000/sec
Testing if a string is a a.b.Q 10,000,000 0.201s 0.020µs 49,700,000/sec
Testing if a Q is a a.b.Q 10,000,000 0.066s 0.007µs 151,000,000/sec
Typeof Builtins
Testing if typeof Array is object 10,000,000 0.029s 0.003µs 344,000,000/sec
Testing if typeof Object is object 10,000,000 0.015s 0.002µs 666,000,000/sec
Testing if typeof Foo is object 10,000,000 0.011s 0.001µs 909,000,000/sec
Testing if typeof String is string 10,000,000 0.012s 0.001µs 833,000,000/sec
Numbers
Check is a string is a number using a regex 1,000,000 -0.048s -0.048µs -20,000,000/sec
Check is a string is a number using charCodeAt 10,000,000 0.049s 0.005µs 204,000,000/sec
Check is a string is a number using charCodeAt (no temp) 10,000,000 0.039s 0.004µs 256,000,000/sec
Check is a string is a number using charAt 10,000,000 0.179s 0.018µs 55,800,000/sec
Check is a string is a number using String prototype 10,000,000 0.213s 0.021µs 46,900,000/sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment