arrayClear.js 455 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. // benchmark ways to clear an Array
  3. // tests
  4. exports.arrayClear = {
  5. beforeEach: function() {
  6. this.arr = Array.apply(0, new Array(1000)).map(function(v, i) {
  7. return i;
  8. });
  9. },
  10. "length === 0": function() {
  11. this.arr.length = 0;
  12. },
  13. "while length, pop": function() {
  14. while (this.arr.length > 0) {
  15. this.arr.pop();
  16. }
  17. },
  18. };
  19. // if run directly run benchmarks
  20. if (!module.parent) require("benchmarksman").runner(exports);