Last active
August 29, 2015 14:14
-
-
Save karussell/e67ffceee2b28c30f248 to your computer and use it in GitHub Desktop.
RAM Cache Test
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
// dependency: graphhopper 0.3 | |
// JVM_OPTS="-Xms2400m -Xmx2400m" | |
// | |
// result on my oldish machine: | |
// separate arrays: GET=34.10 and SET=36.34 | |
// single array: GET=36.34 and SET=34.49 | |
// | |
// => GET is ~7% faster for single array | |
// => SET is ~5% faster for single array | |
// | |
// important: you cannot compare GET and SET because of the '+' | |
class RAMCacheTest | |
{ | |
public static void main( String[] args ) | |
{ | |
final int SIZE = 100 * 1000 * 1000; | |
final int ITER = 10; | |
Directory dir = new RAMDirectory(); | |
final DataAccess da1 = dir.find("test1"); | |
da1.create(4 * SIZE); | |
final DataAccess da2 = dir.find("test2"); | |
da2.create(4 * SIZE); | |
final DataAccess daCombined = dir.find("combined"); | |
daCombined.create(2 * 4 * SIZE); | |
System.out.println("mem " + Helper.getMemInfo()); | |
MiniPerfTest res1 = new MiniPerfTest() | |
{ | |
@Override | |
public int doCalc( boolean warmup, int run ) | |
{ | |
for (int i = 0; i < SIZE; i++) | |
{ | |
long tmp = 4L * i; | |
da1.setInt(tmp, run++); | |
da2.setInt(tmp, -run); | |
} | |
return 0; | |
} | |
}.setIterations(ITER).start(); | |
System.out.println("[separ] per SET call:" + (res1.getMean() / SIZE) * 2000000f + "ns"); | |
MiniPerfTest res2 = new MiniPerfTest() | |
{ | |
@Override | |
public int doCalc( boolean warmup, int run ) | |
{ | |
int res = 0; | |
for (int i = 0; i < SIZE; i++) | |
{ | |
long tmp = 4L * i; | |
res += da1.getInt(tmp) + da2.getInt(tmp); | |
} | |
return res; | |
} | |
}.setIterations(ITER).start(); | |
System.out.println("[separ] per GET call:" + (res2.getMean() / SIZE) * 2000000f + "ns"); | |
MiniPerfTest res3 = new MiniPerfTest() | |
{ | |
@Override | |
public int doCalc( boolean warmup, int run ) | |
{ | |
for (int i = 0; i < SIZE; i++) | |
{ | |
long tmp = 8L * i; | |
daCombined.setInt(tmp, run++); | |
daCombined.setInt(tmp + 4, -run); | |
} | |
return 0; | |
} | |
}.setIterations(ITER).start(); | |
System.out.println("[combi] per SET call:" + (res3.getMean() / SIZE) * 2000000f + "ns"); | |
MiniPerfTest res4 = new MiniPerfTest() | |
{ | |
@Override | |
public int doCalc( boolean warmup, int run ) | |
{ | |
int res = 0; | |
for (int i = 0; i < SIZE; i++) | |
{ | |
long tmp = 8L * i; | |
res += daCombined.getInt(tmp) + daCombined.getInt(tmp + 4); | |
} | |
return res; | |
} | |
}.setIterations(ITER).start(); | |
System.out.println("[combi] per GET call:" + (res4.getMean() / SIZE) * 2000000f + "ns"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment