-
Notifications
You must be signed in to change notification settings - Fork 62
/
PerformanceLogger.java
75 lines (58 loc) · 1.97 KB
/
PerformanceLogger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* This code is released under the
* Apache License Version 2.0 http://www.apache.org/licenses/.
*/
package me.lemire.integercompression.benchmarktools;
/**
* PerformanceLogger for IntegerCODEC.
*
* @author MURAOKA Taro http://github.com/koron
*/
public final class PerformanceLogger {
static class Timer {
private long startNano;
private long duration = 0;
public Timer() {
}
public void start() {
this.startNano = System.nanoTime();
}
public long end() {
return this.duration += System.nanoTime()
- this.startNano;
}
public long getDuration() {
return this.duration;
}
}
final Timer compressionTimer = new Timer();
final Timer decompressionTimer = new Timer();
private long originalSize = 0;
private long compressedSize = 0;
long addOriginalSize(long value) {
return this.originalSize += value;
}
long addCompressedSize(long value) {
return this.compressedSize += value;
}
long getOriginalSize() {
return this.originalSize;
}
long getCompressedSize() {
return this.compressedSize;
}
double getBitPerInt() {
return this.compressedSize * 32.0 / this.originalSize;
}
private static double getMiS(long size, long nanoTime) {
return (size * 1e-6) / (nanoTime * 1.0e-9);
}
double getCompressSpeed() {
return getMiS(this.originalSize,
this.compressionTimer.getDuration());
}
double getDecompressSpeed() {
return getMiS(this.originalSize,
this.decompressionTimer.getDuration());
}
}