forked from pngencoder/pngencoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPngEncoderBenchmarkCompressionSpeedVsSize.java
More file actions
162 lines (134 loc) · 5.58 KB
/
PngEncoderBenchmarkCompressionSpeedVsSize.java
File metadata and controls
162 lines (134 loc) · 5.58 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.pngencoder;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import java.awt.image.BufferedImage;
import java.util.concurrent.TimeUnit;
public class PngEncoderBenchmarkCompressionSpeedVsSize {
private static final Options OPTIONS = new OptionsBuilder()
.include(PngEncoderBenchmarkCompressionSpeedVsSize.class.getSimpleName() + ".*")
.shouldFailOnError(true)
.mode(Mode.Throughput)
.timeUnit(TimeUnit.SECONDS)
.threads(1)
.forks(1)
.warmupIterations(1)
.measurementIterations(1)
.warmupTime(TimeValue.seconds(2))
.measurementTime(TimeValue.seconds(5))
.build();
@Disabled("run manually")
@Test
public void runBenchmarkSpeed() throws Exception {
new Runner(OPTIONS).run();
}
@Disabled("run manually")
@Test
public void runBenchmarkSize() {
final BufferedImage bufferedImage = createTestImage();
for (int compressionLevel = 0; compressionLevel <= 9; compressionLevel++) {
final int fileSize = PngEncoderTestUtil.encodeWithPngEncoder(bufferedImage, compressionLevel);
String message = String.format("compressionLevel: %d fileSize: %d", compressionLevel, fileSize);
System.out.println(message);
}
for (int compressionLevel = 0; compressionLevel <= 9; compressionLevel++) {
final int fileSize = PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(bufferedImage, compressionLevel);
String message = String.format("compressionLevel (withPredictor): %d fileSize: %d", compressionLevel, fileSize);
System.out.println(message);
}
}
@State(Scope.Benchmark)
public static class BenchmarkState {
final BufferedImage bufferedImage = createTestImage();
}
@Benchmark
public void compressionLevel0(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 0);
}
@Benchmark
public void compressionLevel1(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 1);
}
@Benchmark
public void compressionLevel2(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 2);
}
@Benchmark
public void compressionLevel3(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 3);
}
@Benchmark
public void compressionLevel4(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 4);
}
@Benchmark
public void compressionLevel5(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 5);
}
@Benchmark
public void compressionLevel6(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 6);
}
@Benchmark
public void compressionLevel7(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 7);
}
@Benchmark
public void compressionLevel8(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 8);
}
@Benchmark
public void compressionLevel9(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoder(state.bufferedImage, 9);
}
@Benchmark
public void compressionLevel0Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 0);
}
@Benchmark
public void compressionLevel1Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 1);
}
@Benchmark
public void compressionLevel2Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 2);
}
@Benchmark
public void compressionLevel3Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 3);
}
@Benchmark
public void compressionLevel4Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 4);
}
@Benchmark
public void compressionLevel5Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 5);
}
@Benchmark
public void compressionLevel6Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 6);
}
@Benchmark
public void compressionLevel7Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 7);
}
@Benchmark
public void compressionLevel8Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 8);
}
@Benchmark
public void compressionLevel9Predictor(BenchmarkState state) {
PngEncoderTestUtil.encodeWithPngEncoderPredictorEncoding(state.bufferedImage, 9);
}
private static BufferedImage createTestImage() {
return PngEncoderTestUtil.readTestImageResource("png-encoder-logo.png");
}
}