Last active
November 19, 2015 09:58
-
-
Save vbsteven/460527c3f51b91b2ae2a to your computer and use it in GitHub Desktop.
Two Java implementations for a small language benchmark Matthew Jackowski did. http://www.marcinkliks.pl/2015/02/22/swift-vs-others/
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
/** | |
* Created by @vbsteven on 09/10/15. | |
* | |
* Run with "javac TestArray.java && java TestArray" | |
*/ | |
public class TestArray { | |
public static void main(String[] args) { | |
long sum = 0; | |
for (int i = 0; i < 30; i++) { | |
sum = 0; | |
int[] x = new int[1000000]; | |
for (int j = 0; j < 1000000; j++) { | |
x[j] = j; | |
} | |
int[] y = new int[1000000]; | |
for (int j = 0; j < 1000000 - 1; j++) { | |
y[j] = x[j] + x[j + 1]; | |
} | |
for (int j = 0; j < 1000000; j+= 100) { | |
sum += y[j]; | |
} | |
} | |
System.out.println(sum); | |
} | |
} |
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
import java.util.ArrayList; | |
/** | |
* Created by @vbsteven on 09/10/15. | |
* | |
* Run wuth "javac TestArrayList.java && java TestArrayList" | |
*/ | |
public class TestArrayList { | |
public static void main(String[] args) { | |
long sum = 0; | |
for (int i = 0; i < 30; i++) { | |
sum = 0; | |
ArrayList<Integer> x = new ArrayList<Integer>(); | |
for (int j = 0; j < 1000000; j++) { | |
x.add(j); | |
} | |
ArrayList<Integer> y = new ArrayList<>(1000000); | |
for (int j = 0; j < 1000000 - 1; j++) { | |
y.add(x.get(j) + x.get(j + 1)); | |
} | |
for (int j = 0; j < 1000000; j+= 100) { | |
sum += y.get(j); | |
} | |
} | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A visit to this