Skip to content

Commit 9888915

Browse files
committed
Added some test for performance
- ImageTest PNG,GIF,JPG - Ignore jenv's .java-version
1 parent 564f205 commit 9888915

5 files changed

Lines changed: 61 additions & 11 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ local.properties
1313
.recommenders
1414
.project
1515
.classpath
16+
# If you use jenv
17+
.java-version
1618

1719
# External tool builders
1820
.externalToolBuilders/
Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,68 @@
11
package com.lowagie.text;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
34
import static org.junit.jupiter.api.Assertions.assertNotNull;
45

6+
import java.io.IOException;
57
import org.junit.jupiter.api.Test;
68

79
class ImageTest {
810

9-
@Test
10-
void shouldReturnImageWithUrlForUrl() throws Exception {
11-
final Image image = Image.getInstance(ClassLoader.getSystemResource("H.gif"));
12-
assertNotNull(image.getUrl());
13-
}
14-
15-
@Test
16-
void shouldReturnImageWithUrlForPath() throws Exception {
17-
final Image image = Image.getInstance(ClassLoader.getSystemResource("H.gif").getPath());
18-
assertNotNull(image.getUrl());
19-
}
11+
// For performance testing, set this to something > 100
12+
private static final int PERFORMANCE_ITERATIONS = 1;
13+
14+
@Test
15+
void shouldReturnImageWithUrlForUrl() throws Exception {
16+
final Image image = Image.getInstance(ClassLoader.getSystemResource("H.gif"));
17+
assertNotNull(image.getUrl());
18+
}
19+
20+
@Test
21+
void shouldReturnImageWithUrlForPath() throws Exception {
22+
final Image image = Image.getInstance(ClassLoader.getSystemResource("H.gif").getPath());
23+
assertNotNull(image.getUrl());
24+
}
25+
26+
@Test
27+
void performanceTestPng() throws IOException {
28+
long start = System.nanoTime();
29+
Image image = null;
30+
for (int i = 0; i < PERFORMANCE_ITERATIONS; i++) {
31+
image = Image.getInstance(ClassLoader.getSystemResource("imageTest/ImageTest.png").getPath());
32+
}
33+
long deltaMillis = (System.nanoTime() - start) / 1_000_000 / PERFORMANCE_ITERATIONS;
34+
if (PERFORMANCE_ITERATIONS > 1) {
35+
System.out.format("Load PNG ~time after %d iterations %d ms%n", PERFORMANCE_ITERATIONS, deltaMillis);
36+
}
37+
assertNotNull(image.getUrl());
38+
}
39+
40+
@Test
41+
void performanceTestJpg() throws IOException {
42+
long start = System.nanoTime();
43+
Image image = null;
44+
for (int i = 0; i < PERFORMANCE_ITERATIONS; i++) {
45+
image = Image.getInstance(ClassLoader.getSystemResource("imageTest/ImageTest.jpg").getPath());
46+
}
47+
long deltaMillis = (System.nanoTime() - start) / 1_000_000 / PERFORMANCE_ITERATIONS;
48+
if (PERFORMANCE_ITERATIONS > 1) {
49+
System.out.format("Load JPG ~time after %d iterations %d ms%n", PERFORMANCE_ITERATIONS, deltaMillis);
50+
}
51+
assertNotNull(image.getUrl());
52+
}
53+
54+
@Test
55+
void performanceTestGif() throws IOException {
56+
long start = System.nanoTime();
57+
Image image = null;
58+
for (int i = 0; i < PERFORMANCE_ITERATIONS; i++) {
59+
image = Image.getInstance(ClassLoader.getSystemResource("imageTest/ImageTest.gif").getPath());
60+
}
61+
long deltaMillis = (System.nanoTime() - start) / 1_000_000 / PERFORMANCE_ITERATIONS;
62+
if (PERFORMANCE_ITERATIONS > 1) {
63+
System.out.format("Load GIF ~time after %d iterations %d ms%n", PERFORMANCE_ITERATIONS, deltaMillis);
64+
}
65+
assertThat(deltaMillis).isLessThan(200);
66+
assertNotNull(image.getUrl());
67+
}
2068
}
83.6 KB
Loading
72.4 KB
Loading
222 KB
Loading

0 commit comments

Comments
 (0)