1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.stress;
17
18 import junit.framework.TestCase;
19
20 import org.yaml.snakeyaml.Invoice;
21 import org.yaml.snakeyaml.Util;
22 import org.yaml.snakeyaml.Yaml;
23
24
25
26
27 public class ParallelTest extends TestCase {
28 private int progress = 0;
29 private int MAX = 5;
30
31 public void testPerfomance() {
32 String doc = Util.getLocalResource("specification/example2_27.yaml");
33 for (int i = 0; i < MAX; i++) {
34 Worker worker = new Worker(i, doc);
35 Thread thread = new Thread(worker);
36 thread.start();
37 }
38 while (progress < MAX - 1) {
39 try {
40 Thread.sleep(1000);
41 } catch (InterruptedException e) {
42 fail(e.getMessage());
43 }
44 }
45 }
46
47 private class Worker implements Runnable {
48 private int id;
49 private String doc;
50
51 public Worker(int id, String doc) {
52 this.id = id;
53 this.doc = doc;
54 }
55
56 public void run() {
57 System.out.println("Started: " + id);
58 Yaml loader = new Yaml();
59 long time1 = System.nanoTime();
60 int cycles = 200;
61 for (int i = 0; i < cycles; i++) {
62 Invoice invoice = loader.loadAs(doc, Invoice.class);
63 assertNotNull(invoice);
64 }
65 long time2 = System.nanoTime();
66 float duration = ((time2 - time1) / 1000000) / (float) cycles;
67 System.out.println("Duration of " + id + " was " + duration + " ms/load.");
68 progress++;
69 }
70 }
71 }