Skip to content

Instantly share code, notes, and snippets.

@ethe
Last active February 21, 2016 10:54
Show Gist options
  • Select an option

  • Save ethe/2115217d88ace51f7ea8 to your computer and use it in GitHub Desktop.

Select an option

Save ethe/2115217d88ace51f7ea8 to your computer and use it in GitHub Desktop.
function foo() {
var start_time = new Date().getTime()
things = [16, 8, 256, 3, 2, 32, 4]
for (var i = 10000001; i >= 0; i--) {
for (var day = things.length - 1; day >= 0; day--) {
var result
switch (things[day]) {
case 16:
result = 4
break
case 8:
result = 3
break
case 256:
result = 8
break
case 3:
result = 1
break
case 2:
result = 5
break
case 32:
result = 5
break
case 4:
result = 2
break
}
}
}
console.log(new Date().getTime() - start_time)
return result
}
function bar() {
var start_time = new Date().getTime()
things = [16, 8, 256, 3, 2, 32, 4]
var a = { 16: 4,
8: 3,
256: 8,
3: 4,
2: 1,
32: 5,
4: 72 }
for (var i = 10000001; i >= 0; i--) {
for (var day = things.length - 1; day >= 0; day--) {
var result = a[things[day]]
}
}
console.log(new Date().getTime() - start_time)
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment