Tejas Patil
Tejas Patil

Reputation: 6169

java benchmarking : More time for lesser input

After running some benchmarking on 2 regex library implementations, below is the results that we got:

inputs   automaton      regex
 50      343ms          210ms
100      48ms           187ms
200      65ms           363ms
400      100ms          692ms
800      165ms         1385ms

Why the first run (with 50 inputs) is super expensive for both implementations ?

FYI: automation refers to http://www.brics.dk/automaton and 'regex' refers to the java regex library.

Upvotes: 0

Views: 97

Answers (2)

Tejas Patil
Tejas Patil

Reputation: 6169

This is due to the standard micro-benchmark issues with Java.

JVM warmup: Due to several parameters, the code is first often slow and becomes faster and faster when the execution time grows until it goes to steady-state.

Class loading: The first time you launch a benchmark, all the used classes must be loaded, increasing the execution time.

Just In Time Compiler: When the JVM identify a hot part of the code

Garbage Collector: A garbage collection can happen during the benchmark and with that the time can increase a lot.

One good read.

Upvotes: 2

Jan Dörrenhaus
Jan Dörrenhaus

Reputation: 6717

At the beginning, the regex is compiled. So the first run uses extra time. Also, there is probably a run-time optimization going on.

Upvotes: 1

Related Questions