11/*
2- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2424
2525import org .openjdk .jmh .annotations .Benchmark ;
2626import org .openjdk .jmh .annotations .BenchmarkMode ;
27+ import org .openjdk .jmh .annotations .Fork ;
28+ import org .openjdk .jmh .annotations .Measurement ;
2729import org .openjdk .jmh .annotations .Mode ;
2830import org .openjdk .jmh .annotations .OutputTimeUnit ;
2931import org .openjdk .jmh .annotations .Param ;
3032import org .openjdk .jmh .annotations .Scope ;
3133import org .openjdk .jmh .annotations .Setup ;
3234import org .openjdk .jmh .annotations .State ;
35+ import org .openjdk .jmh .annotations .Warmup ;
3336import org .openjdk .jmh .infra .Blackhole ;
3437
3538import java .util .Random ;
3639import java .util .concurrent .TimeUnit ;
3740
3841/**
39- * Tests java.lang.Integer
42+ * Test various java.lang.Integer operations
4043 */
4144@ BenchmarkMode (Mode .AverageTime )
4245@ OutputTimeUnit (TimeUnit .MICROSECONDS )
4346@ State (Scope .Thread )
47+ @ Warmup (iterations = 10 , time = 500 , timeUnit = TimeUnit .MILLISECONDS )
48+ @ Measurement (iterations = 5 , time = 1000 , timeUnit = TimeUnit .MILLISECONDS )
49+ @ Fork (3 )
4450public class Integers {
4551
4652 @ Param ("500" )
4753 private int size ;
4854
4955 private String [] strings ;
56+ private int [] intsSmall ;
57+ private int [] intsBig ;
5058
5159 @ Setup
5260 public void setup () {
5361 Random r = new Random (0 );
5462 strings = new String [size ];
63+ intsSmall = new int [size ];
64+ intsBig = new int [size ];
5565 for (int i = 0 ; i < size ; i ++) {
56- strings [i ] = "" + (r .nextInt (10000 ) - 5000 );
66+ strings [i ] = "" + (r .nextInt (10000 ) - (5000 ));
67+ intsSmall [i ] = 100 * i + i + 103 ;
68+ intsBig [i ] = ((100 * i + i ) << 24 ) + 4543 + i * 4 ;
5769 }
5870 }
5971
@@ -63,4 +75,20 @@ public void parseInt(Blackhole bh) {
6375 bh .consume (Integer .parseInt (s ));
6476 }
6577 }
78+
79+ /** Performs toString on small values, just a couple of digits. */
80+ @ Benchmark
81+ public void toStringSmall (Blackhole bh ) {
82+ for (int i : intsSmall ) {
83+ bh .consume (Integer .toString (i ));
84+ }
85+ }
86+
87+ /** Performs toString on large values, roughly 10 digits. */
88+ @ Benchmark
89+ public void toStringBig (Blackhole bh ) {
90+ for (int i : intsBig ) {
91+ bh .consume (Integer .toString (i ));
92+ }
93+ }
6694}
0 commit comments