Compare speed of f.call(...) vs. %_CallFunction(..., f) in V8
// 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
This comment has been minimized.
Typical output in my machine:
Using
%_CallFunction()
is consistently an order of magnitude faster.