1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
10 * Francis Giraldeau - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.tests
.perf
.synchronization
;
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
;
26 * Test the performance of linear transforms classes
28 * @author Francis Giraldeau
30 public class TimestampTransformBenchmark
{
32 private static final String TEST_ID
= "org.eclipse.linuxtools#Trace synchronization#";
33 private static final String TEST_SUMMARY
= "Timestamp Transform: ";
35 /** Number of transformations done for each transform: 50 millions */
36 private static final long NB_TRANSFORMATIONS
= 50000000L;
39 * Test the timestamp transform performances
42 public void testTimestampTransformPerformance() {
43 ITmfTimestampTransform transform
= TimestampTransformFactory
.getDefaultTransform();
44 doTimestampTransformRun("Identity transform", transform
, 10);
46 transform
= TimestampTransformFactory
.createWithOffset(123456789);
47 doTimestampTransformRun("Transform with offset", transform
, 10);
49 transform
= TimestampTransformFactory
.createLinear(Math
.PI
, 1234);
50 doTimestampTransformRun("Linear transform", transform
, 5);
52 transform
= TimestampTransformFactory
.createLinear(10000.1234545565635, -4312278758437L);
53 doTimestampTransformRun("Linear transform with larger slope and negative offset", transform
, 5);
57 * Benchmark to compare the classic and fast timestamp transform.
59 * Ignore when running automatically, just for local benchmarks.
63 public void testCompareTimestampTransformPerformance() {
65 * We call constructors directly instead of TimestampTransformFactory to
66 * create properly each transform type.
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);
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
);
79 for (int x
= 0; x
< loopCount
; x
++) {
81 * We use timestamps with values in the order of 10^18, which about
82 * corresponds to timestamps in nanoseconds since epoch
84 long time
= (long) Math
.pow(10, 18);
87 * Apply the timestamp transform NB_TRANSFORMATIONS times, with
88 * timestamps incremented by 200 each time
90 for (long i
= 0; i
< NB_TRANSFORMATIONS
; i
++) {
91 xform
.transform(time
);