bench.js 709 B

12345678910111213141516171819202122232425262728293031323334
  1. const FastFIFO = require('./')
  2. const FIFO = require('fifo')
  3. run(new FIFO(), 'fifo')
  4. run(new FastFIFO(), 'fast-fifo')
  5. run(new FIFO(), 'fifo')
  6. run(new FastFIFO(), 'fast-fifo')
  7. function run (q, prefix) {
  8. const runs = 1024
  9. console.time(prefix + ' bulk push and shift')
  10. for (let j = 0; j < 1e5; j++) {
  11. for (let i = 0; i < runs; i++) {
  12. q.push(i)
  13. }
  14. for (let i = 0; i < runs; i++) {
  15. q.shift()
  16. }
  17. }
  18. console.timeEnd(prefix + ' bulk push and shift')
  19. console.time(prefix + ' individual push and shift')
  20. for (let j = 0; j < 1e5; j++) {
  21. for (let i = 0; i < runs; i++) {
  22. q.push(i)
  23. q.shift()
  24. }
  25. }
  26. console.timeEnd(prefix + ' individual push and shift')
  27. }