Created
April 21, 2012 09:42
-
-
Save IvanTorresEdge/2436221 to your computer and use it in GitHub Desktop.
Benchmarking .each and .map functions from jQuery and Underscore.js
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
# 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