Hi everyone
I have the same task implementation on Java and Clojure. Task is very
simple: User input integers to the console. Program need print inputed
integers until user input is 42.
Clojure implementation is 10 times slower, how to optimize Clojure
implementation performance?
Java impl:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
do {
int num = sc.nextInt();
if (num == 42)
break;
System.out.println(num);
} while( true );
}
}
Clojure impl:
(import java.util.Scanner)
(defn getNextInt [scanner term f x]
(if (not= x nil)
(apply f [x]))
(let [val (. scanner nextInt)]
(if (not= val term)
(getNextInt scanner term f val))))
(getNextInt (Scanner. System/in) 42 (fn [x] (println x)) nil)
Thanx
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en