Questions tagged [microbenchmark]

A microbenchmark attempts to measure the performance of a "small" bit of code. These tests are typically in the sub-millisecond range. The code being tested usually performs no I/O, or else is a test of some single, specific I/O task.

Microbenchmarking is very different from profiling! When profiling, you work with an entire application, either in production or in an environment very painstakingly contrived to resemble production. Because of this, you get performance data that is, for lack of a better term, real. When you microbenchmark, you get a result that is essentially fictional, and you must be very careful about what conclusions you draw from it.

Still, for either type always apply the old adage:
Premature optimization is the root of all evil.

485 questions
8
votes
2 answers

Groovy: Is for..in significantly faster than .each?

I'm curious if for..in should be preferred to .each for performance reasons.
Alexander Suraphel
  • 10,103
  • 10
  • 55
  • 90
8
votes
1 answer

What JVM optimization is causing these performance results?

In a Java REST service performance test, I got an unexpected pattern: a method that creates and returns always the same value object in each invocation runs faster than another version that just returns the value object stored in a class or object…
Sebastian
  • 1,835
  • 3
  • 22
  • 34
7
votes
2 answers

Google benchmark with command line args. Writing my own main function?

I have a code that goes something like: ... void benchMark(benchmark::State& state){ maxCapacity = state.range(0); // set up some stuff for (auto _ : state){ // time this code } } BENCHMARK(benchMark)->DenseRange(2, 10,…
Ankit Kumar
  • 1,145
  • 9
  • 30
7
votes
1 answer

Weird performance effects from nearby dependent stores in a pointer-chasing loop on IvyBridge. Adding an extra load speeds it up?

First I have the below setup on an IvyBridge, I will insert measuring payload code in the commented location. The first 8 bytes of buf store the address of buf itself, I use this to create loop-carried dependency: section .bss align 64 buf: …
7
votes
1 answer

What does allocation rate means in JMH

I'm trying to measure the memory consumed when running the benchmark. I found out on the internet that I can use GC profiler to measure that. I tried but I don't understand the answer as well as see the amount of consumed memory. Can anyone explain…
Tri Nguyen
  • 1,688
  • 3
  • 18
  • 46
7
votes
3 answers

Why is strtolower slightly slower than strtoupper?

I did an experiment out of curiosity. I wanted to see if there was a micro difference at all between strtolower() and strtoupper(). I expected strtolower() would be faster on mostly lowercase strings and visa versa. What I found is that strtolower()…
Goose
  • 4,764
  • 5
  • 45
  • 84
7
votes
2 answers

JMH Benchmark get NullPointerException with Autowired field in Spring(with maven) project

I try to benchmark some of the methods of my Spring (with maven) project. I need to use @Autowired and @Inject on several fields in my project. While I run my project, it works well. But JMH always gets NullPointerException with @Autowired/@Inject…
neelrotno
  • 353
  • 1
  • 4
  • 14
7
votes
1 answer

How to get rid of "Method parameters should be @State classes" in JMH when parameters come from another method?

I'm working on a maven project. The scenario is something like below... class Test { public void applyAll() { .................... .................... Collection applicableUpdates =…
neelrotno
  • 159
  • 2
  • 8
7
votes
3 answers

Do Go testing.B benchmarks prevent unwanted optimizations?

I've recently started learning Go and I'm trying to implement a map that can be used concurrently by multiple groutines. I want to be able to compare my implementation to a simple sync.Mutex-protected map, or to something like this:…
Elsinor
  • 190
  • 8
7
votes
3 answers

Bench Mark in Multi threaded environment

I was learning multi threading and found slow down of Object.hashCode in multi threaded environment as it is taking over twice as long to compute the default hash code running 4 threads vs 1 thread for the same number of objects. But as per my…
T-Bag
  • 10,916
  • 3
  • 54
  • 118
7
votes
3 answers

Why is this C++ program slower on Windows than Linux?

Consider the following program: #define _FILE_OFFSET_BITS 64 // Allow large files. #define REVISION "POSIX Revision #9" #include #include #include const int block_size = 1024 * 1024; const char block[block_size] =…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
7
votes
4 answers

JMH not working in Eclipse (as Maven project) - No benchmarks to run

I want to start have a look at JMH and I'm failing to run benchmarks due some reasons. Let me explain what I tried: Setup a maven project in Eclipse Define pom.xml like: Downloaded some official JMH examples. As example I choosed which is pretty…
pitschr
  • 529
  • 1
  • 6
  • 13
6
votes
1 answer

Why does the package qualification of symbols result in less memory used, even if the symbols are imported locally?

Note, I tried testing this before in this question which may look similar, however those results were flawed and a result of constant folding, which I subsequently disabled. and republished in this question. Given these two evals (comment one on…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
6
votes
1 answer

Difference between benchmark and time macro in Julia

I've recently discovered a huge difference between two macros: @benchmark and @time in terms of memory allocation information and time. For example: @benchmark quadgk(x -> x, 0., 1.) BenchmarkTools.Trial: memory estimate: 560 bytes allocs…
Kirill Tsar.
  • 293
  • 1
  • 8
6
votes
2 answers

JMH - weird benchmarking results

I'm using JMH to benchmark DOM parser. I got really weird results as the first iteration actually run faster than later iterations Can anyone explain why this happens? Also, what do percentiles and all the figures mean and why it starts getting…
Tri Nguyen
  • 1,688
  • 3
  • 18
  • 46