|
18 | 18 |
|
19 | 19 | import java.util.List;
|
20 | 20 |
|
21 |
| -import org.junit.Test; |
22 |
| - |
23 | 21 | import com.arangodb.ArangoConfigure;
|
24 | 22 | import com.arangodb.ArangoDriver;
|
25 | 23 | import com.arangodb.ArangoException;
|
|
31 | 29 | *
|
32 | 30 | */
|
33 | 31 | public class BenchmarkImport {
|
34 |
| - |
35 |
| - public static void main(String[] args) throws Exception { |
36 |
| - |
37 |
| - final int max = 10; |
38 |
| - final String collection = "bench-test"; |
39 |
| - ArangoConfigure configure = new ArangoConfigure(); |
40 |
| - configure.init(); |
41 |
| - |
42 |
| - try { |
43 |
| - |
44 |
| - ArangoDriver driver = new ArangoDriver(configure); |
45 |
| - List<Station> stations = TestUtils.readStations(); |
46 |
| - |
47 |
| - // truncate collection |
48 |
| - try { |
49 |
| - driver.truncateCollection("bench-test"); |
50 |
| - } catch (ArangoException e) {} |
51 |
| - |
52 |
| - // Bench import |
53 |
| - BenchLogic logic1 = new BenchImport(driver); |
54 |
| - BenchLogic logic2 = new BenchDocument(driver); |
55 |
| - |
56 |
| - // Bench create document |
57 |
| - long time1 = 0, time2 = 0; |
58 |
| - for (int i = 0; i < max; i++) { |
59 |
| - time1 += logic1.bench(stations); |
60 |
| - time2 += logic2.bench(stations); |
61 |
| - } |
62 |
| - |
63 |
| - System.out.println("import:" + time1); |
64 |
| - System.out.println("document:" + time2); |
65 |
| - |
66 |
| - } finally { |
67 |
| - configure.shutdown(); |
68 |
| - } |
69 |
| - |
70 |
| - } |
71 |
| - |
72 |
| - static private abstract class BenchLogic { |
73 |
| - protected ArangoDriver driver; |
74 |
| - public BenchLogic(ArangoDriver driver) { |
75 |
| - this.driver = driver; |
76 |
| - } |
77 |
| - abstract protected void execute(List<?> values) throws Exception; |
78 |
| - public long bench(List<?> values) throws Exception { |
79 |
| - long t = System.currentTimeMillis(); |
80 |
| - execute(values); |
81 |
| - return System.currentTimeMillis() - t; |
82 |
| - } |
83 |
| - } |
84 |
| - |
85 |
| - static class BenchImport extends BenchLogic { |
86 |
| - public BenchImport(ArangoDriver driver) { |
87 |
| - super(driver); |
88 |
| - } |
89 |
| - @Override |
90 |
| - protected void execute(List<?> values) throws Exception { |
91 |
| - driver.importDocuments("bench-test", true, values); |
92 |
| - } |
93 |
| - } |
94 |
| - |
95 |
| - static class BenchDocument extends BenchLogic { |
96 |
| - public BenchDocument(ArangoDriver driver) { |
97 |
| - super(driver); |
98 |
| - } |
99 |
| - @Override |
100 |
| - protected void execute(List<?> values) throws Exception { |
101 |
| - for (Object value: values) { |
102 |
| - driver.createDocument("bench-test", value, true, false); |
103 |
| - } |
104 |
| - } |
105 |
| - } |
| 32 | + |
| 33 | + final static String COLLECTION_NAME = "bench-test"; |
| 34 | + |
| 35 | + public static void main(String[] args) throws Exception { |
| 36 | + |
| 37 | + final int max = 10; |
| 38 | + ArangoConfigure configure = new ArangoConfigure(); |
| 39 | + configure.init(); |
| 40 | + |
| 41 | + try { |
| 42 | + |
| 43 | + ArangoDriver driver = new ArangoDriver(configure); |
| 44 | + List<Station> stations = TestUtils.readStations(); |
| 45 | + |
| 46 | + // truncate collection |
| 47 | + try { |
| 48 | + driver.truncateCollection(COLLECTION_NAME); |
| 49 | + } catch (ArangoException e) { |
| 50 | + } |
| 51 | + |
| 52 | + // Bench import |
| 53 | + BenchLogic logic1 = new BenchImport(driver); |
| 54 | + BenchLogic logic2 = new BenchDocument(driver); |
| 55 | + |
| 56 | + // Bench create document |
| 57 | + long time1 = 0, time2 = 0; |
| 58 | + for (int i = 0; i < max; i++) { |
| 59 | + time1 += logic1.bench(stations); |
| 60 | + time2 += logic2.bench(stations); |
| 61 | + } |
| 62 | + |
| 63 | + System.out.println("import:" + time1); |
| 64 | + System.out.println("document:" + time2); |
| 65 | + |
| 66 | + } finally { |
| 67 | + configure.shutdown(); |
| 68 | + } |
| 69 | + |
| 70 | + } |
| 71 | + |
| 72 | + static private abstract class BenchLogic { |
| 73 | + protected ArangoDriver driver; |
| 74 | + |
| 75 | + public BenchLogic(ArangoDriver driver) { |
| 76 | + this.driver = driver; |
| 77 | + } |
| 78 | + |
| 79 | + abstract protected void execute(List<?> values) throws Exception; |
| 80 | + |
| 81 | + public long bench(List<?> values) throws Exception { |
| 82 | + long t = System.currentTimeMillis(); |
| 83 | + execute(values); |
| 84 | + return System.currentTimeMillis() - t; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + static class BenchImport extends BenchLogic { |
| 89 | + public BenchImport(ArangoDriver driver) { |
| 90 | + super(driver); |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + protected void execute(List<?> values) throws Exception { |
| 95 | + driver.importDocuments(COLLECTION_NAME, true, values); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + static class BenchDocument extends BenchLogic { |
| 100 | + public BenchDocument(ArangoDriver driver) { |
| 101 | + super(driver); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + protected void execute(List<?> values) throws Exception { |
| 106 | + for (Object value : values) { |
| 107 | + driver.createDocument("bench-test", value, true, false); |
| 108 | + } |
| 109 | + } |
| 110 | + } |
106 | 111 |
|
107 | 112 | }
|
0 commit comments