_.values

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.1/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js
">
</script>
<script>
var lodash = _.noConflict();

_.mixin({
  'myvalues': function(obj) {
    return _.map(_.keys(obj), function(key){
      return obj[key];
    });
  }
});

function Obj() {
    this.key1 ='value1';
    this.key2 ='value2';
    this.key3 ='value3';
    this.key4 ='value4';
    this.key5 ='value5';
    this.key6 ='value6';
    this.key7 ='value7';
    this.key8 ='value8';
    this.key9 ='value9';
    this.key10 ='value10';
    this.key11 ='value11';
    this.key12 ='value12';
    this.key13 ='value13';
    this.key14 ='value14';
    this.key15 ='value15';
    this.key16 ='value16';
    this.key17 ='value17';
    this.key18 ='value18';
    this.key19 ='value19';
    this.key20 ='value20';
    this.key21 ='value21';
    this.key22 ='value22';
    this.key23 ='value23';
    this.key24 ='value24';
    this.key25 ='value25';
    this.key26 ='value26';
    this.key27 ='value27';
    this.key28 ='value28';
    this.key29 ='value29';
    this.key30 ='value30';
    this.key31 ='value31';
    this.key32 ='value32';
    this.key33 ='value33';
    this.key34 ='value34';
    this.key35 ='value35';
    this.key36 ='value36';
    this.key37 ='value37';
    this.key38 ='value38';
    this.key39 ='value39';
    this.key40 ='value40';
    this.key41 ='value41';
    this.key42 ='value42';
    this.key43 ='value43';
    this.key44 ='value44';
    this.key45 ='value45';
    this.key46 ='value46';
    this.key47 ='value47';
    this.key48 ='value48';
    this.key49 ='value49';
    this.key50 ='value50';
    this.key51 ='value51';
    this.key52 ='value52';
    this.key53 ='value53';
    this.key54 ='value54';
    this.key55 ='value55';
    this.key56 ='value56';
    this.key57 ='value57';
    this.key58 ='value58';
    this.key59 ='value59';
    this.key60 ='value60';
    this.key61 ='value61';
    this.key62 ='value62';
    this.key63 ='value63';
    this.key64 ='value64';
    this.key65 ='value65';
    this.key66 ='value66';
    this.key67 ='value67';
    this.key68 ='value68';
    this.key69 ='value69';
    this.key70 ='value70';
    this.key71 ='value71';
    this.key72 ='value72';
    this.key73 ='value73';
    this.key74 ='value74';
    this.key75 ='value75';
    this.key76 ='value76';
    this.key77 ='value77';
    this.key78 ='value78';
    this.key79 ='value79';
    this.key80 ='value80';
    this.key81 ='value81';
    this.key82 ='value82';
    this.key83 ='value83';
    this.key84 ='value84';
    this.key85 ='value85';
    this.key86 ='value86';
    this.key87 ='value87';
    this.key88 ='value88';
    this.key89 ='value89';
    this.key90 ='value90';
    this.key91 ='value91';
    this.key92 ='value92';
    this.key93 ='value93';
    this.key94 ='value94';
    this.key95 ='value95';
    this.key96 ='value96';
    this.key97 ='value97';
    this.key98 ='value98';
    this.key99 ='value99';
    this.key100 ='value100';

}
var object = new Obj();
var l = 1e4;
while(l--){
_.values(object);
_.myvalues(object);
lodash.values(object);
}

</script>
<script>
Benchmark.prototype.setup = function() {
    var _ = window._,
        lodash = window.lodash,
        object = new Obj();
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
original
_.values(object);
pending…
my implement
_.myvalues(object);
pending…
lodash
lodash.values(object);
pending…

Compare results of other browsers

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:

0 comments

Add a comment