Created
December 3, 2014 19:07
-
-
Save aperezdc/b1b5dab48eeb1dcfadc8 to your computer and use it in GitHub Desktop.
Compare speed of f.call(...) vs. %_CallFunction(..., f) in V8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run with: d8 --allow-natives-syntax callfunction.js | |
function f1(n, cb, thisArg) { | |
for (var i = 0; i < n; i++) { | |
cb.call(thisArg, i); | |
} | |
} | |
function f2(n, cb, thisArg) { | |
for (var i = 0; i < n; i++) { | |
%_CallFunction(thisArg, i, cb); | |
} | |
} | |
var start; | |
var end; | |
function callback(i) { /* no-op */ } | |
start = new Date().getTime(); | |
f1(10000000, callback, 42); | |
end = new Date().getTime(); | |
print("f1", end - start, "ms"); | |
start = new Date().getTime(); | |
f2(10000000, callback, 42); | |
end = new Date().getTime(); | |
print("f2", end - start, "ms"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Typical output in my machine:
Using
%_CallFunction()
is consistently an order of magnitude faster.