The same code, but using the new standard: http://cr.openjdk.java.net/~chegar/docs/portingScript.html
How is the new standard I thought that I should create new thread. Sorry. On Sun, Jan 25, 2015 at 10:30 PM, Claes Redestad <claes.redes...@oracle.com> wrote: > Wait a minute. Is this the latest? Why start a new thread? > > Updating your benchmark to the latest JMH and running them against the > latest JDK9 I get contradictory > results (repeatable on two different machines): > > Benchmark (param) Mode Cnt Score Error Units > > .indexOfChar 10000 thrpt 50 3875.096 ± 12.365 ops/s > .indexOfString 10000 thrpt 50 4523.693 ± 9.835 ops/s > > JMH 1.5 version: > > import org.openjdk.jmh.annotations.*; > import org.openjdk.jmh.infra.Blackhole; > ... > private static final String WORDS = "I love java Language 8 because > has Lambda, Stream and MetaSpace"; > > @Param("10000") > private int param; > > @Benchmark > public void indexOfString(Blackhole bh) { > for (int i = 0; i <= param; i++) { > int index = WORDS.indexOf(","); > bh.consume(index); > } > } > > @Benchmark > public void indexOfChar(Blackhole bh) { > for (int i = 0; i <= param; i++) { > int index = WORDS.indexOf(','); > bh.consume(index); > } > } > > Turning WORDS into public String words actually narrows the gap (doesn't > really make sense to > benchmark indexOf with a literal char/String on a literal String, IMHO): > > Char: 5.158 ± 0.052 ops/ms > String: 5.314 ± 0.052 ops/ms > > Writing the benchmark like this: > > public String words = "I love java Language 8 because has Lambda, > Stream and MetaSpace"; > > @Benchmark > public int indexOfString() { > return words.indexOf(","); > } > > @Benchmark > public int indexOfChar() { > return words.indexOf(','); > } > > shows some possible benefit: > > Char 50.962 ± 0.529 ops/us > String 44.765 ± 0.078 ops/us > > Comparing with results from older JDKs, it seems something must've subtly > changed - perhaps > a regression somewhere. Turning off > > The fact that there's no indexOf(char) but rather an indexOf(int), while > this area is a > minefield of intrinsics makes all of this very hard to evaluate from a > performance point of view. > > Also, I think everyone would appreciate if you could split the patch into > one patch per module. > That'd be a natural split and will simplify getting reviews from each > appropriate team. > > /Claes > > On 2015-01-12 23:23, Otávio Gonçalves de Santana wrote: > >> These String literals may be replaced by equivalent character literals[1], >> gaining some performance enhancement. >> >> Webrev: >> https://dl.dropboxusercontent.com/u/16109193/open_jdk/jdk/ >> index_of_character/index.html >> >> >> [1] >> @State(Scope.Thread) >> @OutputTimeUnit(TimeUnit.SECONDS) >> public class IndexOfBenchmark { >> >> private static final String WORDS = "I love java Language 8 because >> has >> Lambda, Stream and MetaSpace"; >> >> @Param("10000") >> private int param; >> >> @GenerateMicroBenchmark >> public void indexOfString(BlackHole bh) { >> >> for (int i = 0; i <= param; i++) { >> int index = WORDS.indexOf(","); >> bh.consume(index); >> } >> } >> >> @GenerateMicroBenchmark >> public void indexOfChar(BlackHole bh) { >> >> for (int i = 0; i <= param; i++) { >> int index = WORDS.indexOf(','); >> bh.consume(index); >> } >> } >> } >> >> Benchmark (param) Mode Samples Mean >> Mean error Units >> m.IndexOfBenchmark.indexOfChar 10000 thrpt 10 5579.120 >> 114.179 ops/s >> m.IndexOfBenchmark.indexOfString 10000 thrpt 10 4562.178 >> 46.751 ops/s >> >> > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513