This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
/
PerfTests.java
164 lines (142 loc) · 5.72 KB
/
PerfTests.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
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
163
164
/**
* Copyright (C) 2011-2014 Michael Vogt <michu@neophob.com>
*
* This file is part of PixelController.
*
* PixelController is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PixelController is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PixelController. If not, see <http://www.gnu.org/licenses/>.
*/
package com.neophob.sematrix.core.perf;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.Adler32;
import net.jpountz.xxhash.XXHash32;
import net.jpountz.xxhash.XXHashFactory;
import com.neophob.sematrix.core.resize.IResize;
import com.neophob.sematrix.core.resize.PixelControllerResize;
import com.neophob.sematrix.core.resize.Resize.ResizeName;
import com.neophob.sematrix.core.visual.MatrixData;
import com.neophob.sematrix.core.visual.Visual;
import com.neophob.sematrix.core.visual.color.ColorSet;
import com.neophob.sematrix.core.visual.color.IColorSet;
import com.neophob.sematrix.core.visual.effect.Effect;
import com.neophob.sematrix.core.visual.effect.Inverter;
import com.neophob.sematrix.core.visual.generator.Generator;
import com.neophob.sematrix.core.visual.generator.Plasma2;
import com.neophob.sematrix.core.visual.mixer.AddSat;
import com.neophob.sematrix.core.visual.mixer.Mixer;
public class PerfTests {
private static final Logger LOG = Logger.getLogger(PerfTests.class.getName());
private int pixelSize;
private int rounds;
private int smallRound;
private byte[] data;
private long t1;
public PerfTests(int rounds, int pixelSize) {
this.rounds = rounds;
this.smallRound = rounds / 200;
if (smallRound == 0) {
smallRound = 1;
}
this.pixelSize = pixelSize;
this.data = new byte[pixelSize * pixelSize * 2];
for (int i = 0; i < this.data.length; i++) {
this.data[i] = (byte) (i);
}
LOG.log(Level.INFO,
"\n\nPerformance test using {0} rounds and pixelsize of {1} ({2} buffer size).",
new Object[] { rounds, pixelSize, data.length });
}
private long measureAdler32Hash() {
preTest();
Adler32 adler = new Adler32();
for (int i = 0; i < rounds; i++) {
adler.reset();
adler.update(data);
adler.getValue();
}
return postTest();
}
private long measureXXHash() {
preTest();
XXHashFactory factory = XXHashFactory.fastestInstance();
XXHash32 hash32 = factory.hash32();
for (int i = 0; i < rounds; i++) {
hash32.hash(data, 0, data.length, 0x9747b28c);
}
return postTest();
}
private long measureVisual() {
preTest();
MatrixData matrix = new MatrixData(pixelSize, pixelSize);
Generator g = new Plasma2(matrix);
Effect e = new Inverter(matrix);
Mixer m = new AddSat();
IColorSet c = new ColorSet("pillepalle", new int[] { 0, 0x0000ff, 0x00ff00, 0xff0000,
0xffffff });
Visual v = new Visual(g, e, m, c);
for (int i = 0; i < smallRound; i++) {
v.getBuffer();
}
return postTest();
}
private void measureResize() {
int largeSize = pixelSize * 8;
int smallSize = pixelSize;
LOG.log(Level.INFO,
"Pixel Resize: {0} rounds, output buffer: {1} bytes, visual buffer: {2} bytes",
new Object[] { smallRound, smallSize * smallSize, largeSize * largeSize });
PixelControllerResize pcr = new PixelControllerResize();
pcr.initAll();
IResize res = pcr.getResize(ResizeName.PIXEL_RESIZE);
preTest();
int[] buffer = new int[largeSize * largeSize];
for (int i = 0; i < smallRound; i++) {
res.resizeImage(buffer, largeSize, largeSize, smallSize, smallSize);
}
long time = postTest();
long timePerResize = time * 1000L / smallRound;
LOG.log(Level.INFO, ">>> PixelResize needed {0}ms - {1}ns per resize", new Object[] { time,
timePerResize });
res = pcr.getResize(ResizeName.QUALITY_RESIZE);
preTest();
buffer = new int[largeSize * largeSize];
for (int i = 0; i < smallRound; i++) {
res.resizeImage(buffer, largeSize, largeSize, smallSize, smallSize);
}
time = postTest();
timePerResize = time * 1000L / smallRound;
LOG.log(Level.INFO, ">>> QualityResize needed {0}ms - {1}ns per resize", new Object[] {
time, timePerResize });
}
private void preTest() {
this.t1 = System.currentTimeMillis();
}
private long postTest() {
return System.currentTimeMillis() - t1;
}
public void startPerfTest() {
long t = measureAdler32Hash();
long timePerHash = t * 1000L / rounds;
LOG.log(Level.INFO, ">>> Adler32 Hash: {0}ms - {1}ns per hash", new Object[] { t,
timePerHash });
t = measureXXHash();
timePerHash = t * 1000L / rounds;
LOG.log(Level.INFO, ">>> XXHash: {0}ms - {1}ns per hash", new Object[] { t, timePerHash });
t = measureVisual();
long timePerResize = t * 1000L / smallRound;
LOG.log(Level.INFO, ">>> Visual needed {0}ms - {1}ns per getBuffer call", new Object[] { t,
timePerResize });
measureResize();
}
}