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
22
votes
13 answers

Java for loop performance question

considering this example: public static void main(final String[] args) { final List myList = Arrays.asList("A", "B", "C", "D"); final long start = System.currentTimeMillis(); for (int i = 1000000; i > myList.size(); i--) { …
kukudas
  • 4,834
  • 5
  • 44
  • 65
22
votes
2 answers

Understanding the output of -XX:+PrintCompilation

I am running some micro benchmarks on Java list iteration code. I have used -XX:+PrintCompilation, and -verbose:gc flags to ensure that nothing is happening in the background when the timing is being run. However, I see something in the output which…
Parag
  • 12,093
  • 16
  • 57
  • 75
21
votes
2 answers

Why is logarithm slower in Rust than in Java?

If I run these benchmarks in Rust: #[bench] fn bench_rnd(b: &mut Bencher) { let mut rng = rand::weak_rng(); b.iter(|| rng.gen_range::(2.0, 100.0)); } #[bench] fn bench_ln(b: &mut Bencher) { let mut rng = rand::weak_rng(); …
21
votes
3 answers

shade for parameter resource: Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer

I'm working on a maven project. I'm trying to integrate jmh benchmarking into my project. The pom.xml of my maven project... platform platform-root 3.0-SNAPSHOT
neelrotno
  • 353
  • 1
  • 4
  • 14
21
votes
1 answer

google microbenchmarking cpu scaling warning

When I run the google benchmark I get a WARNING saying that cpu scaling is enabled. Is that a feature that I can toggle at build via flags or at runtime via arguments or is it a system setting?
Tandura
  • 866
  • 2
  • 7
  • 19
20
votes
1 answer

What does autoplot.microbenchmark actually plot?

According to the docs, microbenchmark:::autoplot "Uses ggplot2 to produce a more legible graph of microbenchmark timings." Cool! Let's try the example code: library("ggplot2") tm <- microbenchmark(rchisq(100, 0), rchisq(100,…
bright-star
  • 6,016
  • 6
  • 42
  • 81
20
votes
3 answers

Why the bounds check doesn't get eliminated?

I wrote a simple benchmark in order to find out if bounds check can be eliminated when the array gets computed via bitwise and. This is basically what nearly all hash tables do: They compute h & (table.length - 1) as an index into the table, where…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
19
votes
2 answers

"Escape" and "Clobber" equivalent in MSVC

In Chandler Carruth's CppCon 2015 talk he introduces two magical functions for defeating the optimizer without any extra performance penalties. For reference, here are the functions (using GNU-style inline assembly): void escape(void* p) { asm…
helloworld922
  • 10,801
  • 5
  • 48
  • 85
18
votes
3 answers

Why is String.strip() 5 times faster than String.trim() for blank string In Java 11

I've encountered an interesting scenario. For some reason strip() against blank string (contains whitespaces only) significantly faster than trim() in Java 11. Benchmark public class Test { public static final String TEST_STRING = " "; // 3…
Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
18
votes
1 answer

Strange JIT pessimization of a loop idiom

While analyzing the results of a recent question here, I encountered a quite peculiar phenomenon: apparently an extra layer of HotSpot's JIT-optimization actually slows down execution on my machine. Here is the code I have used for the…
Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
17
votes
2 answers

perf enable demangling of callgraph

How do I enable C++ demangling for the perf callgraph? It seems to demangle symbols when I go into annotate mode, but not in the main callgraph. Sample code (using Google Benchmark): #include #include static…
helloworld922
  • 10,801
  • 5
  • 48
  • 85
16
votes
20 answers

My python program executes faster than my java version of the same program. What gives?

Update: 2009-05-29 Thanks for all the suggestions and advice. I used your suggestions to make my production code execute 2.5 times faster on average than my best result a couple of days ago. In the end I was able to make the java code the…
Blaine Osepchuk
  • 1,067
  • 1
  • 9
  • 17
16
votes
1 answer

Why is my Rust program slower than the equivalent Java program?

I was playing around with binary serialization and deserialization in Rust and noticed that binary deserialization is several orders of magnitude slower than with Java. To eliminate the possibility of overhead due to, for example, allocations and…
Ben Sidhom
  • 1,548
  • 16
  • 25
14
votes
4 answers

On improving Haskell's performance compared to C in fibonacci micro-benchmark

I came across this question, which compared the performance of various compilers on computing fibonaci numbers the naive way. I tried doing this with Haskell to see how it compares to C. C code: #include #include int fib (int…
Phil
  • 5,595
  • 5
  • 35
  • 55
14
votes
1 answer

Idiomatic way of performance evaluation?

I am evaluating a network+rendering workload for my project. The program continuously runs a main loop: while (true) { doSomething() drawSomething() doSomething2() sendSomething() } The main loop runs more than 60 times per second. I…
shpark
  • 369
  • 2
  • 7
1
2
3
32 33