views:

780

answers:

3

Javascript Objects and JScript Dictionary are both associative Arrays

obj = new Object ;
dic = new ActiveXObject("Scripting.Dictionary") ;

My question is... Is there any difference between them in terms of efficiency (either space or time) ??
In terms of functionality, I know a Dictionary is better because it allows more than just scalar types as keys. But putting that aside, which one is better/faster?

EDIT:
This is for Windows scripting, not for web development.

EDIT2:
I'm particularly interested in the lookup efficiency, since I'll need to work with big collections.

+2  A: 

Scripting.Dictionary is a COM/ActiveX component (can be used in any of MS scripting languages).

I wouldn't recommend it because every time you access it, you're calling into the COM component, which is very slow.

But if you need its functionality, you can use it, but beware that it only works in IE...

Philippe Leybaert
Question tags specify that it's for running in WSH, so only windows, no browser...
Tetsujin no Oni
Just to expand on that a little - Scipting.Dictionary is not JavaScript, it just has a JavaScript interface in IE.
David Dorward
Just to say I think it's important to note the IE part just for anyone who reads this without noticing WSH (like I did :P)
annakata
+2  A: 

Javascript objects are inherent in the execution engine; Scripting.Dictionary is a COM object doing interop calls on every operation.

For anything in javascript, I would tend to prefer using the in-engine type unless I had a tremendous need for a lookup based on some other COM object with good equality semantics...

Tetsujin no Oni
What about the search time? I was thinking on very big arrays, where the time spent in searching a given key-value pair is the most important factor.
GetFree
That'd depend on whether I was running a loop on keys, or doing lookups. If your use case has performance issues due to the size of the dataset you're scanning, perhaps a scripting language isn't where you want to be.
Tetsujin no Oni
+2  A: 

It appears from this document that the lookup is quicker using Dictionary; however the inserts are slower.

http://www.4guysfromrolla.com/webtech/100800-1.2.shtml

TJ
What's the deal?! The accepted answer is marked down?
TJ