tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / perf / org / eclipse / tracecompass / tmf / core / tests / perf / synchronization / TimestampTransformBenchmark.java
1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Francis Giraldeau - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.core.tests.perf.synchronization;
14
15 import org.eclipse.test.performance.Dimension;
16 import org.eclipse.test.performance.Performance;
17 import org.eclipse.test.performance.PerformanceMeter;
18 import org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfTimestampTransformLinear;
19 import org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfTimestampTransformLinearFast;
20 import org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform;
21 import org.eclipse.tracecompass.tmf.core.synchronization.TimestampTransformFactory;
22 import org.junit.Ignore;
23 import org.junit.Test;
24
25 /**
26 * Test the performance of linear transforms classes
27 *
28 * @author Francis Giraldeau
29 */
30 public class TimestampTransformBenchmark {
31
32 private static final String TEST_ID = "org.eclipse.linuxtools#Trace synchronization#";
33 private static final String TEST_SUMMARY = "Timestamp Transform: ";
34
35 /** Number of transformations done for each transform: 50 millions */
36 private static final long NB_TRANSFORMATIONS = 50000000L;
37
38 /**
39 * Test the timestamp transform performances
40 */
41 @Test
42 public void testTimestampTransformPerformance() {
43 ITmfTimestampTransform transform = TimestampTransformFactory.getDefaultTransform();
44 doTimestampTransformRun("Identity transform", transform, 10);
45
46 transform = TimestampTransformFactory.createWithOffset(123456789);
47 doTimestampTransformRun("Transform with offset", transform, 10);
48
49 transform = TimestampTransformFactory.createLinear(Math.PI, 1234);
50 doTimestampTransformRun("Linear transform", transform, 5);
51
52 transform = TimestampTransformFactory.createLinear(10000.1234545565635, -4312278758437L);
53 doTimestampTransformRun("Linear transform with larger slope and negative offset", transform, 5);
54 }
55
56 /**
57 * Benchmark to compare the classic and fast timestamp transform.
58 *
59 * Ignore when running automatically, just for local benchmarks.
60 */
61 @Ignore
62 @Test
63 public void testCompareTimestampTransformPerformance() {
64 /*
65 * We call constructors directly instead of TimestampTransformFactory to
66 * create properly each transform type.
67 */
68 ITmfTimestampTransform classic = new TmfTimestampTransformLinear(Math.PI, 1234);
69 ITmfTimestampTransform fast = new TmfTimestampTransformLinearFast(Math.PI, 1234);
70 doTimestampTransformRun("Linear transform classic", classic, 5);
71 doTimestampTransformRun("Linear transform fast", fast, 5);
72 }
73
74 private static void doTimestampTransformRun(String testName, ITmfTimestampTransform xform, long loopCount) {
75 Performance perf = Performance.getDefault();
76 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName);
77 perf.tagAsSummary(pm, TEST_SUMMARY + testName, Dimension.CPU_TIME);
78
79 for (int x = 0; x < loopCount; x++) {
80 /**
81 * We use timestamps with values in the order of 10^18, which about
82 * corresponds to timestamps in nanoseconds since epoch
83 */
84 long time = (long) Math.pow(10, 18);
85 pm.start();
86 /**
87 * Apply the timestamp transform NB_TRANSFORMATIONS times, with
88 * timestamps incremented by 200 each time
89 */
90 for (long i = 0; i < NB_TRANSFORMATIONS; i++) {
91 xform.transform(time);
92 time += 200;
93 }
94 pm.stop();
95 }
96 pm.commit();
97 }
98
99 }
This page took 0.109334 seconds and 5 git commands to generate.