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