thread local allocation in benchmark

閲覧: 12 回
最初の未読メッセージにスキップ

Dan Burkert

未読、
2013/07/25 10:45:242013/07/25
To: cal...@googlegroups.com
I'm having trouble benchmarking some code that calls String.getBytes().  Behind the scenes this method caches some string encoder classes in a ThreadLocal.  When I try to benchmark, say something as simple as:

    @Benchmark
    public long bench(int reps) throws Exception {
        long dummy = 0;
        for (int i = 0; i < reps; i++) {
            dummy |= "foobar".getBytes().hashCode();
        }
        return dummy;
    }

the benchmark run fails with

java.lang.IllegalStateException: Your benchmark appears to have non-deterministic allocation behavior.

But even if I call String.getBytes() in a static field initializer in the benchmarking class (in order to pre-load the class caches), the benchmark still fails with the same exception.  I believe it is because the benchmarks are being run on a different thread.  Anyone know any way around this problem?  Thanks.

Gregory Kick

未読、
2013/07/29 13:40:052013/07/29
To: cal...@googlegroups.com
I think you have a few options:
1) I think that the simple way to address the problem would be to explicitly pass in the Charset.  (It's a best practice anyway: https://plus.google.com/u/0/118010414872916542489/posts/FGpFSai9dVo)
2) Call your benchmark method explicitly from a @BeforeExperiment method. Since they are guaranteed to run first, that should initialize the data.


HTH


--
--
guava-...@googlegroups.com
Project site: http://caliper.googlecode.com
This group: http://groups.google.com/group/caliper
 
This list is for general discussion.
To report an issue: http://code.google.com/p/caliper/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "caliper")
 
---
You received this message because you are subscribed to the Google Groups "caliper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caliper+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Greg Kick
Java Core Libraries Team
全員に返信
投稿者に返信
転送
新着メール 0 件