# Sugar vs Underscore!

## JavaScript performance comparison

Revision 3 of this test case created by Ceane Lamerez and last updated

## What's faster?

I really like Sugar.JS however Underscore.js is very popular and seems to have stronger following. Now it's time to see which is faster!

## Preparation code

<script src="https://underscorejs.org/underscore-min.js">
</script>
<script src="https://sugarjs.com/current/sugar-full.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {

Arr = [0, 3, 1, 6, 9, 34, 3, 34, 32, 234, 3424, 234, 234, 56, 67, 29, 26, 521, 37, 23, 46, 73, 23, 32, 234, 7, 1];
Object.keys=Object.keys||function(o,r){r=[];for(r[r.length] in o);return r}
applier = function(num) {
return num * 2;
}
var containsObj = function (arr) {var x=arr.length; while (x--) {if (typeof arr[x] === 'object') return true } return false;}

var dullArr = function(arr,p) {var x=arr.length, i=x, cx= true; while(void(arr[i]==undefined?'':cx=false), cx!=false && i--); return cx;};

var deep = function (o, fn) {return o}
var o = function (o, fn) {
if (containsObj(o)) {return deep(o, fn);}
var set = function () {a[i] = fn(o[i]); i += 1;}
var i = 0, n = o.length, a = new Array(n);
do set();
while (i < n);
i=0;
return a;
}
map = o;

}
</script>

## Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
_.map
var result = _.map(Arr, applier)
pending…
Object.map
var result = Object.map(Arr, applier)
pending…
map()
var result = map(Arr, applier)
pending…

## Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

• Revision 1: published by Ceane Lamerez
• Revision 3: published by Ceane Lamerez and last updated
• Revision 4: published by Ceane Lamerez
• Revision 6: published by Mike
• Revision 7: published by Flamefork
• Revision 8: published
• Revision 9: published
• Revision 10: published
• Revision 11: published

# 1 comment

tomByrer commented :

May I suggest you try out http://lodash.com/? It is like Underscore 2.0, usually faster & more compatible.

Comment form temporarily disabled.