Random: native vs lodash vs underscore (v3)

Revision 3 of this benchmark created on


Description

Correct version of wierd test...

Preparation HTML

<script src="//cdn.jsdelivr.net/lodash/2.4.1/lodash.underscore.min.js"></script>
<script>
var ld = _.noConflict();
</script>
<script src="//cdn.jsdelivr.net/underscorejs/1.5.2/underscore-min.js"></script>
<script>
var us = _.noConflict();
</script>

Setup

var getRandomArrayNative = function(from, to, number) {
      var result = [],
        r = 0;
      for (var i = 0; i < number; i++) {
        do {
          r = Math.floor(Math.random() * (to - from + 1) + from);
        } while (result.indexOf(r) !== -1)
        result.push(r);
      }
      return result;
    };
    
    var getRandomArrayLodash = function(number) {
      var result = ld.shuffle(a);
      return result.splice(0, number - 1);
    };
    
    var getRandomArrayUnderscore = function(number) {
      var result = us.shuffle(a);
      return result.splice(0, number - 1);
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Native Random
getRandomArrayNative(1, 50, 5);
ready
Lodash Random
getRandomArrayLodash(5);
ready
Underscore Random
getRandomArrayUnderscore(5);
ready

Revisions

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