comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/profiles/CountingConditionProfileTest.java @ 22501:a63bda98cfdb

Extract profiles into separate package. Add isProfilingEnabled in TruffleRuntime to disable profiling in the default runtime; Add low overhead profiles for primitives; Add LoopConditionProfile; Profile footprint/threadsafety improvements; Make toString implementations more consistent; Greatly enhanced javadoc documentation for profiles; Deprecate old profiles
author Christian Humer <christian.humer@oracle.com>
date Wed, 16 Dec 2015 16:38:13 +0100
parents truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/utilities/CountingConditionProfileTest.java@b39b603e2a1e
children 4ba1aa33fda4
comparison
equal deleted inserted replaced
22500:fbe1eb7b4172 22501:a63bda98cfdb
1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.api.profiles;
24
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.junit.Assert.assertThat;
27
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.experimental.theories.DataPoints;
31 import org.junit.experimental.theories.Theories;
32 import org.junit.experimental.theories.Theory;
33 import org.junit.runner.RunWith;
34
35 @RunWith(Theories.class)
36 public class CountingConditionProfileTest {
37
38 @DataPoints public static boolean[] data = new boolean[]{true, false};
39
40 private ConditionProfile.Counting profile;
41
42 @Before
43 public void create() {
44 profile = (ConditionProfile.Counting) ConditionProfile.Counting.create();
45 }
46
47 @Test
48 public void testInitial() {
49 assertThat(profile.getTrueCount(), is(0));
50 assertThat(profile.getFalseCount(), is(0));
51 profile.toString();
52 }
53
54 @Theory
55 public void testProfileOne(boolean value) {
56 boolean result = profile.profile(value);
57
58 assertThat(result, is(value));
59 assertThat(profile.getTrueCount(), is(value ? 1 : 0));
60 assertThat(profile.getFalseCount(), is(!value ? 1 : 0));
61 profile.toString();
62 }
63
64 @Theory
65 public void testProfileTwo(boolean value0, boolean value1) {
66 boolean result0 = profile.profile(value0);
67 boolean result1 = profile.profile(value1);
68
69 assertThat(result0, is(value0));
70 assertThat(result1, is(value1));
71 assertThat(profile.getTrueCount(), is((value0 ? 1 : 0) + (value1 ? 1 : 0)));
72 assertThat(profile.getFalseCount(), is((!value0 ? 1 : 0) + (!value1 ? 1 : 0)));
73 profile.toString();
74 }
75
76 @Theory
77 public void testProfileThree(boolean value0, boolean value1, boolean value2) {
78 boolean result0 = profile.profile(value0);
79 boolean result1 = profile.profile(value1);
80 boolean result2 = profile.profile(value2);
81
82 assertThat(result0, is(value0));
83 assertThat(result1, is(value1));
84 assertThat(result2, is(value2));
85 assertThat(profile.getTrueCount(), is((value0 ? 1 : 0) + (value1 ? 1 : 0) + (value2 ? 1 : 0)));
86 assertThat(profile.getFalseCount(), is((!value0 ? 1 : 0) + (!value1 ? 1 : 0) + (!value2 ? 1 : 0)));
87 profile.toString();
88 }
89
90 }