blob: 5d7528bcfe05e0c30d22f80596bcfbc190f837d4 [file] [log] [blame]
Elliott Hughes97aba272013-02-13 16:21:51 -08001/*
2 * Copyright (C) 2010 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package benchmarks;
18
Elliott Hughes97aba272013-02-13 16:21:51 -080019/**
20 * What do various kinds of addition cost?
21 */
Paul Duffinea13f822015-11-30 11:09:55 +000022public class AdditionBenchmark {
Elliott Hughes97aba272013-02-13 16:21:51 -080023 public int timeAddConstantToLocalInt(int reps) {
24 int result = 0;
25 for (int i = 0; i < reps; ++i) {
26 result += 123;
27 }
28 return result;
29 }
30 public int timeAddTwoLocalInts(int reps) {
31 int result = 0;
32 int constant = 123;
33 for (int i = 0; i < reps; ++i) {
34 result += constant;
35 }
36 return result;
37 }
38 public long timeAddConstantToLocalLong(int reps) {
39 long result = 0;
40 for (int i = 0; i < reps; ++i) {
41 result += 123L;
42 }
43 return result;
44 }
45 public long timeAddTwoLocalLongs(int reps) {
46 long result = 0;
47 long constant = 123L;
48 for (int i = 0; i < reps; ++i) {
49 result += constant;
50 }
51 return result;
52 }
53 public float timeAddConstantToLocalFloat(int reps) {
54 float result = 0.0f;
55 for (int i = 0; i < reps; ++i) {
56 result += 123.0f;
57 }
58 return result;
59 }
60 public float timeAddTwoLocalFloats(int reps) {
61 float result = 0.0f;
62 float constant = 123.0f;
63 for (int i = 0; i < reps; ++i) {
64 result += constant;
65 }
66 return result;
67 }
68 public double timeAddConstantToLocalDouble(int reps) {
69 double result = 0.0;
70 for (int i = 0; i < reps; ++i) {
71 result += 123.0;
72 }
73 return result;
74 }
75 public double timeAddTwoLocalDoubles(int reps) {
76 double result = 0.0;
77 double constant = 123.0;
78 for (int i = 0; i < reps; ++i) {
79 result += constant;
80 }
81 return result;
82 }
83}