Created
October 27, 2009 21:38
-
-
Save digash/219980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment