Last active
January 1, 2016 08:29
-
-
Save tkfm-yamaguchi/8119017 to your computer and use it in GitHub Desktop.
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
### | |
# $ coffee -c loop.coffee ; nodejs loop.js | |
### | |
measure = (title, f) -> | |
begin = new Date() | |
f() | |
console.log "#{title}: #{(new Date() - begin)}" | |
times = 10000000 | |
array = [1..times] | |
# AVG: 395 | |
things = undefined | |
measure "Array.push", -> | |
things = [] | |
for factor in array | |
things.push factor | |
# To avoid that coffee creates an anonymous array | |
# for the return value of this function. | |
return things | |
# AVG: 360 | |
things = undefined | |
measure "inline", -> | |
things = (x for x in array) |
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
### | |
# $ coffee -c loop.coffee ; nodejs loop.js | |
### | |
measure = (title, f) -> | |
begin = new Date() | |
f() | |
console.log "#{title}: #{(new Date() - begin)}" | |
times = 10000000 | |
array = [1..times] | |
# AVG: 400 | |
things = undefined | |
measure "inline", -> | |
things = (x for x in array) | |
# AVG: 355 | |
things = undefined | |
measure "Array.push", -> | |
things = [] | |
for factor in array | |
things.push factor | |
# To avoid that coffee creates an anonymous array | |
# for the return value of this function. | |
return things | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment