Last active
January 26, 2016 19:14
-
-
Save hrj/94784fc6af4b49a112a0 to your computer and use it in GitHub Desktop.
Benchmarks for doppio
This file contains hidden or 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
| public class Compute { | |
| public static void main(String args[]) { | |
| final long start = System.currentTimeMillis(); | |
| final long ans = rep(8000); | |
| final long end = System.currentTimeMillis(); | |
| System.out.println(ans); | |
| System.out.println("Time taken (ms): " + (end - start)); | |
| } | |
| public static long rep(long n) { | |
| long sum = 0L; | |
| for (int i = 0; i < n; i++) { | |
| sum += fib(i % 73); | |
| if (sum % 7 < 4) { | |
| sum -= fib(i % 53); | |
| } | |
| } | |
| return sum; | |
| } | |
| public static long fib(long n) { | |
| long prev = 0L; | |
| long curr = 1L; | |
| for (int i = 0; i <= n; i++) { | |
| final long b = curr; | |
| curr += prev; | |
| prev = b; | |
| } | |
| return curr; | |
| } | |
| } |
This file contains hidden or 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
| import javax.tools.*; | |
| import java.io.*; | |
| public class FrozenCompile { | |
| public static void main(String args[]) { | |
| final long start = System.currentTimeMillis(); | |
| final int ans = compile("Test", "public class Test {}"); | |
| final long end = System.currentTimeMillis(); | |
| System.out.println(ans); | |
| System.out.println("Time taken (ms): " + (end - start)); | |
| } | |
| private static void writeToFile(final File path, final String data) throws IOException{ | |
| try(final java.io.FileWriter fileWriter = new java.io.FileWriter(path)) { | |
| fileWriter.write(data); | |
| } | |
| } | |
| public static int compile(final String className, final String scriptText) { | |
| try { | |
| final String filePath = "/tmp/" + className + ".java"; | |
| writeToFile(new File(filePath), scriptText); | |
| final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); | |
| final String[] compileData = {"-d", "/tmp", filePath}; | |
| System.out.println("Compiling: " + java.util.Arrays.toString(compileData)); | |
| final int result = compiler.run(null, null, null, compileData); | |
| return result; | |
| } catch (final IOException e) { | |
| e.printStackTrace(); | |
| return -1; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment