Java Performance measurement

前端 未结 6 961
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 03:53

I am doing some Java performance comparison between my classes, and wondering if there is some sort of Java Performance Framework to make writing performance measurement cod

6条回答
  •  青春惊慌失措
    2020-12-10 04:10

    You probably want to move the loop into the task. As it is you just start all the threads and almost immediately you're back to single threaded.

    Usual microbenchmarking advice: Allow for some warm up. As well as average, deviation is interesting. Use System.nanoTime instead of System.currentTimeMillis.

    Specific to this problem is how much the threads fight. With a large number of contending threads, cas loops can perform wasted work. Creating a SecureRandom is probably expensive, and so might System.currentTimeMillis to a lesser extent. I believe SecureRandom should already be thread safe, if used correctly.

提交回复
热议问题