Hello,
a colleague of mine asked me a question about clojures set
implementation performance. He needed an immutable set on the jvm
platform for a Java/Scala project, and since I've been saying that
Clojures data structures have good performance he tried clojures set.
He was dissapointed though :-(

He sent me this program testing performance:

for (int j = 0; j < 10; j++) {
  long t = System.currentTimeMillis();
  PersistentHashSet persistentSet = PersistentHashSet.create();
  Set<Object> mutableJavaSet = new HashSet<Object>();
  for (int i = 0; i < 500000; i++) {
    Object o = new Object();
    persistentSet = (PersistentHashSet) persistentSet.cons(o);
    mutableJavaSet.add(o);
  }
  System.out.println("filling set took " + (System.currentTimeMillis()
- t) + "ms");

  long start = System.currentTimeMillis();
  for (Object o : persistentSet) {
    o.toString();
  }
  System.out.println("clojure time: " + (System.currentTimeMillis() -
start) + " ms");

  long t1 = System.currentTimeMillis();
  for (Object o : mutableJavaSet) {
    o.toString();
  }
  System.out.println("java time: " + (System.currentTimeMillis() - t1)
+ " ms");
}

What was surprising to me wasn't that "inserts" are slower - that is
ok and it could be improved with transients. The surprising thing was
that iterating through the entire set was significantly slower.

I realize that there is some overhead in producing a seq but I wasn't
expecting it to be that much (4-18 times slower). Also, are chunked
seqs used here - as far as I can tell they aren't? IF not, couldn't
they?

Insights wanted :-)

/Karl

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to