11

I guess they're the same thing but Clojure uses the Array class to manipulate.

Anyway, I've been told that in Clojure if you really need speed then you can use arrays but between the following programs the Java version is much faster

(time
 (let [data (int-array 100000000)]
   (dotimes [q 100000000]
     (aset-int data q q))))

_

public class Array{
    public static void main(String[] args){
    long start = System.currentTimeMillis();
    int[] data = new int[100000000];
    for(int q = 0;q < data.length;q++){
        data[q] = q;
    }
    System.out.println(System.currentTimeMillis() - start);
    }
}

In contrast, this Clojure program that uses the IntBuffer class is almost as fast as the Java code

(time
 (let [data (IntBuffer/allocate 100000000)]
   (dotimes [q 100000000]
     (.put data q q))))
1
  • 1
    Would you mind publishing your results? Commented Jun 1, 2011 at 8:43

1 Answer 1

10

Don't use aset-* functions. Just use aset: (aset data q q). Don't ask me why the aset-* functions are there. As long as I can remember their use was discouraged.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 because the same benchmark with aset ran about ten times faster. Did not compare with Java version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.