Ticket #170 (new enhancement)

Opened 2 years ago

Last modified 1 year ago

Queue and Stack

Reported by: paul@nafpik.com Assigned to: paul@nafpik.com
Priority: normal Milestone: MochiKit 1.5
Component: component1 Version:
Severity: normal Keywords:
Cc: hartshorne@gmail.com

Description

Test and possibly optimize these Queue, Stack and AsyncQueue implementations before committing. Also, where should Queue and Stack go?

Attachments

queue.js (2.1 kB) - added by paul@nafpik.com on 08/29/06 15:40:30.
initial implementation

Change History

08/29/06 15:40:30 changed by paul@nafpik.com

  • attachment queue.js added.

initial implementation

08/29/06 16:06:51 changed by beau@hartshornesoftware.com

Browsers are all over the place, I don't know if it's worth re-implementing this. The numbers don't seem to be as good on Mac and Windows (ran several times each, took the median time):

Safari:

q = new Queue(); t1 = new Date(); for (i = 0; i < 10000; i++) { q.put(i); q.get(); }; t2 = new Date(); t2 - t1

1027

a = new Array(); t1 = new Date(); for (i = 0; i < 10000; i++) { a.push(i); a.shift(); }; t2 = new Date(); t2 - t1

30

FF Mac:

q = new Queue(); t1 = new Date(); for (i = 0; i < 10000; i++) { q.put(i); q.get(); }; t2 = new Date(); t2 - t1

226

a = new Array(); t1 = new Date(); for (i = 0; i < 10000; i++) { a.push(i); a.shift(); }; t2 = new Date(); t2 - t1

172

IE 6:

q = new Queue(); t1 = new Date(); for (i = 0; i < 10000; i++) { q.put(i); q.get(); }; t2 = new Date(); t2 - t1

90

a = new Array(); t1 = new Date(); for (i = 0; i < 10000; i++) { a.push(i); a.shift(); }; t2 = new Date(); t2 - t1

50

08/29/06 16:39:56 changed by paul@nafpik.com

Bizarre. I think I've run up against some screwiness in the way Firebug evaluates things; Queue is reliably quite a bit faster there, but not with essentially the same test in the same browser if run from the page's Javascript directly.

So I take back the claim that Queue is faster for such small sequence cases. Apparently it only is in the odd alternate universe of the Firebug console.

Still, it doesn't need to be always faster than Array in order to be useful.

01/06/07 16:55:47 changed by roosmaa@gmail.com

Are those implementations really faster than: var queue = []; queue.push (foo); var bar = queue.shift (); /* foo == bar */ var stack = []; stack.push (foo); var bar = stack.pop (); /* foo == bar */

And even if they are abit faster why reinvent the wheel?

05/14/07 17:43:13 changed by rsayre@mozilla.com

  • milestone set to MochiKit 1.5.