TMF: Add benchmarks for timestamp transforms
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / perf / org / eclipse / linuxtools / 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.linuxtools.tmf.core.tests.perf.synchronization;
14
15 import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
16 import org.eclipse.linuxtools.tmf.core.synchronization.TimestampTransformFactory;
17 import org.eclipse.test.performance.Dimension;
18 import org.eclipse.test.performance.Performance;
19 import org.eclipse.test.performance.PerformanceMeter;
20 import org.junit.Test;
21
22 /**
23 * Test the performance of linear transforms classes
24 *
25 * @author Francis Giraldeau
26 */
27 public class TimestampTransformBenchmark {
28
29 private static final String TEST_ID = "org.eclipse.linuxtools#Trace synchronization#";
30 private static final String TEST_SUMMARY = "Timestamp Transform: ";
31
32 /** Number of transformations done for each transform: 50 millions */
33 private static final long NB_TRANSFORMATIONS = 50000000L;
34
35 /**
36 * Test the timestamp transform performances
37 */
38 @Test
39 public void testTimestampTransformPerformance() {
40 ITmfTimestampTransform transform = TimestampTransformFactory.getDefaultTransform();
41 doTimestampTransformRun("Identity transform", transform, 10);
42
43 transform = TimestampTransformFactory.createWithOffset(123456789);
44 doTimestampTransformRun("Transform with offset", transform, 10);
45
46 transform = TimestampTransformFactory.createLinear(Math.PI, 1234);
47 doTimestampTransformRun("Linear transform", transform, 5);
48
49 transform = TimestampTransformFactory.createLinear(10000.1234545565635, -4312278758437L);
50 doTimestampTransformRun("Linear transform with larger slope and negative offset", transform, 5);
51 }
52
53 private static void doTimestampTransformRun(String testName, ITmfTimestampTransform xform, long loopCount) {
54 Performance perf = Performance.getDefault();
55 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName);
56 perf.tagAsSummary(pm, TEST_SUMMARY + testName, Dimension.CPU_TIME);
57
58 for (int x = 0; x < loopCount; x++) {
59 /**
60 * We use timestamps with values in the order of 10^18, which about
61 * corresponds to timestamps in nanoseconds since epoch
62 */
63 long time = (long) Math.pow(10, 18);
64 pm.start();
65 /**
66 * Apply the timestamp transform NB_TRANSFORMATIONS times, with
67 * timestamps incremented by 200 each time
68 */
69 for (long i = 0; i < NB_TRANSFORMATIONS; i++) {
70 xform.transform(time);
71 time += 200;
72 }
73 pm.stop();
74 }
75 pm.commit();
76 }
77
78 }
This page took 0.032654 seconds and 5 git commands to generate.