Skip to content

Instantly share code, notes, and snippets.

@theY4Kman
Last active October 23, 2015 17:11
Show Gist options
  • Select an option

  • Save theY4Kman/5cab6bc97c8b42e9ce84 to your computer and use it in GitHub Desktop.

Select an option

Save theY4Kman/5cab6bc97c8b42e9ce84 to your computer and use it in GitHub Desktop.
ITERATIONS = 10000
measure = (title, o) ->
table =
'lodash keys': do ->
# lodash keys()
begin = performance.now()
for i in [1..ITERATIONS]
_.keys(o)
performance.now() - begin
'null': do ->
# null shalow test
begin = performance.now()
for i in [1..ITERATIONS]
o?
performance.now() - begin
console.log('With', title, '--')
console.log("#{k}:", v) for k, v of table
measure('an empty object', {})
measure('a few keys', {a: 1, b: 2, c: 3})
o = {}
o["key-#{i}"] = "value #{i}" for i in [1..1000]
measure('a thousand keys', o)
###
VM1027:2 With an empty object --
VM1027:2 lodash keys: 20.864999999990687
VM1027:2 null: 0.11499999999068677
VM1027:2 With a few keys --
VM1027:2 lodash keys: 7.310000000055879
VM1027:2 null: 0.06999999994877726
VM1027:2 With a thousand keys --
VM1027:2 lodash keys: 897.1599999999162
VM1027:2 null: 0.060000000055879354
###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment