digash (owner)

Revisions

gist: 219980 Download_button fork
public
Public Clone URL: git://gist.github.com/219980.git
Embed All Files: show embed
CompiledFilter.java #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.polarsparc.clojure;
 
import java.util.Random;
 
import clojure.lang.RT;
import clojure.lang.Var;
 
public class CompiledFilter {
private static int[] nums;
    private static Var filterEvenGt500;
 
public static void main(final String[] args) {
if (args.length != 1) {
System.out.printf("Usage: java %s <filter-even-gt-500 | filter-odd-gt-500>\n", CompiledFilter.class.getName());
System.exit(1);
}
init(args[0]);
execute();
}
 
public static void init(final String name) {
try {
RT.loadResourceScript("filters.clj");
filterEvenGt500 = RT.var("filters", name);
 
nums = new int[100];
final Random rand = new Random();
for (int i = 0; i < 100; ++i) {
nums[i] = rand.nextInt(1000);
}
} catch (final Throwable ex) {
ex.printStackTrace(System.err);
System.exit(1);
}
}
 
public static void execute() {
try {
final long stm = System.currentTimeMillis();
for (final int n : nums) {
if (RT.booleanCast(filterEvenGt500.invoke(n))) {
System.out.printf("CompiledFilter: %d\n", n);
}
}
final long etm = System.currentTimeMillis();
System.out.printf("CompiledFilter execute time: %d ms\n", (etm-stm));
}
catch (final Throwable ex) {
ex.printStackTrace(System.err);
System.exit(1);
}
}
}