Created
July 28, 2015 17:42
-
-
Save Chadtech/7f12bb0aa47708a3d46d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
_ = require 'lodash' | |
# | |
# Good ol' while statement | |
# | |
bunchOfNumbers = [0 .. 1000000] | |
start = new Date().getMinutes() | |
start *= 60 | |
start += new Date().getSeconds() | |
start *= 1000 | |
start += new Date().getMilliseconds() | |
time = 0 | |
while time < bunchOfNumbers.length | |
bunchOfNumbers[ time ]++ | |
time++ | |
end = new Date().getMinutes() | |
end *= 60 | |
end += new Date().getSeconds() | |
end *= 1000 | |
end += new Date().getMilliseconds() | |
console.log "DURATION OF WHILE", (end - start) | |
# | |
# Lo dash Map | |
# | |
bunchOfNumbers = [0 .. 1000000] | |
start = new Date().getMinutes() | |
start *= 60 | |
start += new Date().getSeconds() | |
start *= 1000 | |
start += new Date().getMilliseconds() | |
bunchOfNumbers = _.map bunchOfNumbers, (number) -> | |
number + 1 | |
end = new Date().getMinutes() | |
end *= 60 | |
end += new Date().getSeconds() | |
end *= 1000 | |
end += new Date().getMilliseconds() | |
console.log "DURATION OF MAP", (end - start) | |
# | |
# native map | |
# | |
bunchOfNumbers = [0 .. 1000000] | |
start = new Date().getMinutes() | |
start *= 60 | |
start += new Date().getSeconds() | |
start *= 1000 | |
start += new Date().getMilliseconds() | |
bunchOfNumbers.map (number) -> | |
number + 1 | |
end = new Date().getMinutes() | |
end *= 60 | |
end += new Date().getSeconds() | |
end *= 1000 | |
end += new Date().getMilliseconds() | |
console.log "DURATION OF NATIVE MAP", (end - start) | |
# | |
# Results are usually around | |
# While : 3 | |
# Lodash Map : 150 | |
# Native Map : 165 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment