Skip to content

Instantly share code, notes, and snippets.

@IvanTorresEdge
Created April 21, 2012 09:42
Show Gist options
  • Save IvanTorresEdge/2436221 to your computer and use it in GitHub Desktop.
Save IvanTorresEdge/2436221 to your computer and use it in GitHub Desktop.
Benchmarking .each and .map functions from jQuery and Underscore.js
# Benchmarking .each and .map functions from jQuery and Underscore.js
#
# Requirements:
# npm install benchmark jquery underscore
Benchmark = new require('benchmark')
$ = require 'jQuery'
_ = require 'underscore'
# each
o = [1,2,3,4,5,6,7,8,9,0]
suite = new Benchmark.Suite()
suite.add '$.each', ->
$.each o, (i, n) -> n + 1
suite.add '_.each', ->
_.each o, (i, n) -> n + 1
suite.on 'complete', ->
console.log @filter('fastest').pluck('name')
suite.run()
# map
suite = new Benchmark.Suite()
suite.add '$.map', ->
$.map o, (n) -> n + 1
suite.add '_.map', ->
_.map o, (n) -> n + 1
suite.on 'complete', ->
console.log @filter('fastest').pluck('name')
suite.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment