dfjgh

JavaScript performance comparison

Test case created by geoffreyTools

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  Array.prototype.split_from = function (n) {
   return Array.from(
    {length: Math.ceil(this.length / n)}, 
    (a, i) => {const j = i*n; return this.slice(j, j + n)}
   );
  }
  Array.prototype.split_slice = function (n) {
  	let l = Math.ceil(this.length / n);
  	const arr = new Array(l);
  	let j = l * n;
  	while(l) {
  		arr[--l] = this.slice(j - n, j);
  		j -= n;
  	}
  	return arr;
  }
  Array.prototype.split_copy = function (n) {
  	const l = this.length;
  	const groups = new Array(Math.ceil(l / n));
  	let i = 1, mod = 1, g = 0;
  	groups[0] = [this[0]];
  	while(i < l) {
  		if(mod === 0) {
  			groups[++g] = [this[i]];
  		} else {
  			groups[g][mod] = this[i];
  		}
  		i++;
  		mod = i % n;
  	};
  	return groups;
  }
  const arr = Array.from({length: 2000}, (x, i) => i);

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
split from
arr.split_from(10);
pending…
split slice
arr.split_slice(10)
pending…
split copy
arr.split_copy(10)
pending…

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

0 Comments