_dotvalues

JavaScript performance comparison

Test case created by N

Preparation code

<script src="http://lodash.com/_js/lodash.compat.js"></script>
<script>lodash = _.noConflict();</script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var uvalues = _.values;
    var lvalues = lodash.values;
    var nvalues = function(obj) {
        return _.map(_.keys(obj), function(key){
            return obj[key];
        });
    }
    function makeid()
    {
        var text = "";
        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
   
        for( var i=0; i < 10; i++ )
            text += possible.charAt(Math.floor(Math.random() * possible.length));
   
        return text;
    }
    var data = [];
    for (var i = 0; i < 500; ++i) {
      data[makeid()] = i;
    }
};
</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
liuyl's values
var ari = [];
var i = 0;
for (val in nvalues(data))
  ari.push(++i + ' - ' + val);
console.log(ari.join());
pending…
_.values
var ary = [];
var i = 0;
for (val in uvalues(data))
  ary.push(++i + ' - ' + val);
console.log(ary.join());
pending…
lodash.values
var ary = [];
var i = 0;
for (val in lvalues(data))
  ary.push(++i + ' - ' + val);
console.log(ary.join());
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment