Skip to content

Commit 7cf15f1

Browse files
authored
Start benchmark suite, fix operations that require multiple inputs (#100)
* Fix operations that require more than one input image * Start benchmark suite
1 parent 17db8c3 commit 7cf15f1

File tree

22 files changed

+721
-409
lines changed

22 files changed

+721
-409
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repositories {
2121
}
2222

2323
dependencies {
24-
implementation("app.photofox.vips-ffm:vips-ffm-core:0.5.14")
24+
implementation("app.photofox.vips-ffm:vips-ffm-core:0.6.0")
2525
}
2626
```
2727
When running your project you must add `--enable-native-access=ALL-UNNAMED` to your JVM runtime arguments. If you

core/build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ testing {
4747
useKotlinTest("2.0.0")
4848
testType = TestSuiteType.INTEGRATION_TEST
4949

50+
dependencies {
51+
implementation(project(":core"))
52+
implementation("org.openjdk.jmh:jmh-core:1.37")
53+
annotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.37")
54+
}
55+
5056
targets {
5157
all {
5258
testTask.configure {
@@ -69,7 +75,6 @@ tasks.withType<Test> {
6975

7076
tasks.named("check") {
7177
dependsOn(testing.suites.named("test"))
72-
dependsOn(testing.suites.named("integrationTest"))
7378
}
7479

7580
tasks.withType<JavaExec>().configureEach {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package app.photofox.vipsffm;
2+
3+
import app.photofox.vipsffm.enums.VipsInteresting;
4+
import org.junit.jupiter.api.Test;
5+
import org.openjdk.jmh.annotations.*;
6+
import org.openjdk.jmh.runner.Runner;
7+
import org.openjdk.jmh.runner.options.OptionsBuilder;
8+
import org.openjdk.jmh.runner.options.TimeValue;
9+
10+
import java.lang.foreign.Arena;
11+
import java.util.concurrent.TimeUnit;
12+
13+
public class BenchmarkTests {
14+
15+
@Test
16+
void runBenchmarks() throws Exception {
17+
var options = new OptionsBuilder()
18+
.include(this.getClass().getName() + ".*")
19+
.mode(Mode.AverageTime)
20+
.timeUnit(TimeUnit.MILLISECONDS)
21+
.warmupIterations(3)
22+
.measurementTime(TimeValue.seconds(1))
23+
.measurementIterations(10)
24+
.threads(1)
25+
.forks(1)
26+
.shouldFailOnError(true)
27+
.shouldDoGC(true)
28+
.build();
29+
30+
new Runner(options).run();
31+
}
32+
33+
@State(Scope.Thread)
34+
public static class BenchmarkState {
35+
36+
VSource sourceImage;
37+
Arena arena = Arena.ofConfined();
38+
39+
@Setup(Level.Trial)
40+
public void init() throws VipsError {
41+
Vips.init(false, true);
42+
VipsHelper.cache_set_max(0);
43+
44+
sourceImage = VSource.newFromFile(
45+
arena,
46+
"../sample/src/main/resources/sample_images/fox.jpg"
47+
);
48+
}
49+
50+
@TearDown
51+
public void tearDown() {
52+
arena.close();
53+
Vips.shutdown();
54+
}
55+
}
56+
57+
@Benchmark
58+
public void thumbnailOnly(BenchmarkState state) {
59+
Vips.run(arena -> {
60+
var target = VTarget.newToMemory(arena);
61+
var image = VImage.newFromSource(arena, state.sourceImage, "");
62+
image
63+
.thumbnailImage(400)
64+
.writeToTarget(target, ".jpg");
65+
});
66+
}
67+
68+
@Benchmark
69+
public void jvipsStyle(BenchmarkState state) {
70+
Vips.run(arena -> {
71+
var target = VTarget.newToMemory(arena);
72+
var image = VImage.newFromSource(arena, state.sourceImage, "");
73+
var insertSize = 512;
74+
var paddingSize = 100;
75+
var finalImageSize = insertSize + paddingSize;
76+
var backgroundImage = VImage.newImage(arena)
77+
.black(finalImageSize, finalImageSize);
78+
var insertImage = image
79+
.thumbnailImage(
80+
insertSize,
81+
VipsOption.Int("height", insertSize),
82+
VipsOption.Enum("crop", VipsInteresting.INTERESTING_CENTRE)
83+
);
84+
backgroundImage
85+
.insert(insertImage, paddingSize / 2, paddingSize / 2)
86+
.writeToTarget(target, ".jpg");
87+
});
88+
}
89+
}

0 commit comments

Comments
 (0)