1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.yaml.snakeyaml.stress;
18
19 import java.io.IOException;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24
25 import org.yaml.snakeyaml.Invoice;
26 import org.yaml.snakeyaml.Util;
27 import org.yaml.snakeyaml.Yaml;
28
29 public class StressEmitterTest extends TestCase {
30
31 public static void main(String args[]) {
32 junit.textui.TestRunner.run(suite());
33 }
34
35 public static Test suite() {
36 return new TestSuite(StressEmitterTest.class);
37 }
38
39 public void testPerformance() throws IOException {
40 Yaml loader = new Yaml();
41 Invoice invoice = loader.loadAs(Util.getLocalResource("specification/example2_27.yaml"),
42 Invoice.class);
43 Yaml dumper = new Yaml();
44 long time1 = System.nanoTime();
45 dumper.dumpAsMap(invoice);
46 long time2 = System.nanoTime();
47 float duration = (time2 - time1) / 1000000;
48 System.out.println("\nSingle dump was " + duration + " ms.");
49
50 int[] range = new int[] { 1000, 2000
51 System.out.println("\nOne instance.");
52 for (int number : range) {
53 time1 = System.nanoTime();
54 for (int i = 0; i < number; i++) {
55 dumper.dump(invoice);
56 }
57 time2 = System.nanoTime();
58 duration = ((time2 - time1) / 1000000) / (float) number;
59 System.out.println("Duration for r=" + number + " was " + duration + " ms/dump.");
60
61 if (duration > 3) {
62 System.err.println("!!!!!! Too long. Expected <1 but was " + duration);
63 }
64 }
65
66 System.out.println("\nMany instances.");
67 for (int number : range) {
68 time1 = System.nanoTime();
69 for (int i = 0; i < number; i++) {
70 dumper = new Yaml();
71 dumper.dumpAsMap(invoice);
72 }
73 time2 = System.nanoTime();
74 duration = ((time2 - time1) / 1000000) / (float) number;
75 System.out.println("Duration for r=" + number + " was " + duration + " ms/dump.");
76
77 if (duration > 3) {
78 System.err.println("!!!!!! Too long. Expected <1 but was " + duration);
79 }
80
81 }
82 }
83 }