arrayClear.js 451 B

1234567891011121314151617181920212223242526
  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) this.arr.pop();
  15. },
  16. };
  17. // if run directly run benchmarks
  18. if (!module.main) return require("benchmarksman").runner(exports);