Browse files

Improve CacheEvaluation

  • Loading branch information...
1 parent d880ed9 commit 4978d38c395329515cbf25402d86155ab5090ec8 Daniel Gómez Ferro committed Feb 19, 2013
Showing with 21 additions and 11 deletions.
  1. +21 −11 src/main/java/com/yahoo/omid/tso/CacheEvaluation.java
View
32 src/main/java/com/yahoo/omid/tso/CacheEvaluation.java
@@ -7,13 +7,14 @@
public class CacheEvaluation {
- final int entries = 1000000;
- Histogram hist = new Histogram(entries * 100);
+ final static int ENTRIES = 1000000;
+ final static int WARMUP_ROUNDS = 20;
+ final static int ROUNDS = 20;
+ Histogram hist = new Histogram(ENTRIES * 100);
- // @Test
public void testEntriesAge(int asoc, PrintWriter writer) {
- LongCache cache = new LongCache(entries, asoc);
+ LongCache cache = new LongCache(ENTRIES, asoc);
Random random = new Random();
long seed = random.nextLong();
@@ -27,15 +28,19 @@ public void testEntriesAge(int asoc, PrintWriter writer) {
int i = 0;
int largestDeletedTimestamp = 0;
- for (; i < entries * 10; ++i) {
+ for (; i < ENTRIES * WARMUP_ROUNDS; ++i) {
long removed = cache.set(random.nextLong(), i);
if (removed > largestDeletedTimestamp) {
largestDeletedTimestamp = (int) removed;
}
+ if (i % ENTRIES == 0) {
+ int round = i / ENTRIES + 1;
+ System.err.format("Warmup [%d/%d]\n", round, WARMUP_ROUNDS);
+ }
}
long time = System.nanoTime();
- for (; i < entries * 100; ++i) {
+ for (; i < ENTRIES * (WARMUP_ROUNDS + ROUNDS); ++i) {
long removed = cache.set(random.nextLong(), i);
if (removed > largestDeletedTimestamp) {
largestDeletedTimestamp = (int) removed;
@@ -47,17 +52,22 @@ public void testEntriesAge(int asoc, PrintWriter writer) {
tempAvg += (gap - tempAvg) / removals;
tempStdDev += (gap - oldAvg) * (gap - tempAvg);
hist.add(gap);
+ if (i % ENTRIES == 0) {
+ int round = i / ENTRIES - WARMUP_ROUNDS + 1;
+ System.err.format("Progress [%d/%d]\n", round, ROUNDS);
+ }
}
long elapsed = System.nanoTime() - time;
- double elapsedSeconds = (elapsed / (double) 1000000000);
+ double elapsedSeconds = (elapsed / (double) 1000000000);
+ long totalOps = ENTRIES * ROUNDS;
writer.println("# Elapsed (s): " + elapsedSeconds);
- writer.println("# Elapsed per 100 ops (ms): " + (elapsed / (double) entries / (double) 1000000));
- writer.println("# Ops per s : " + ((entries * 100) / elapsedSeconds));
+ writer.println("# Elapsed per 100 ops (ms): " + (elapsed / (double) totalOps / 100 / (double) 1000000));
+ writer.println("# Ops per s : " + (totalOps / elapsedSeconds));
double avgAge = totalAge / (double) removals;
// LOG.info("Avg gap: " + (avgAge ));
writer.println("# Avg gap: " + (tempAvg));
- writer.println("# Std dev gap: " + Math.sqrt((tempStdDev / entries)));
+ writer.println("# Std dev gap: " + Math.sqrt((tempStdDev / ENTRIES)));
hist.print(writer);
// System.out.println(hist.toString());
// assertThat(avgAge, is(greaterThan(entries * .9 )));
@@ -66,7 +76,7 @@ public void testEntriesAge(int asoc, PrintWriter writer) {
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
int[] asoc = new int[] { 1, 2, 4, 8, 16, 32 };
for (int i = 0; i < asoc.length; ++i) {
- PrintWriter writer = new PrintWriter(asoc[i] + ".txt", "UTF-8");
+ PrintWriter writer = new PrintWriter(asoc[i] + ".out", "UTF-8");
new CacheEvaluation().testEntriesAge(asoc[i], writer);
writer.close();
}

0 comments on commit 4978d38

Please sign in to comment.