2009/6/19 Mark Thomas <ma...@apache.org>: > > I've made the changes you suggested and lo and behold the ThreadLocal is > quicker. > >> testAccessLogGetDate: 16 threads and 10000000 iterations using Syncs >> took 7461ms >> testAccessLogGetDate: 16 threads and 10000000 iterations using >> ThreadLocals took 6433ms > > Out of interest, how many cores are you running? With 4 cores I get a > bigger difference: > org.apache.catalina.valves.Benchmarks$TimeDateElementBenchmarkTest_Sync: > 16 threads and 10000000 iterations using Syncs took 14359ms > org.apache.catalina.valves.Benchmarks$TimeDateElementBenchmarkTest_Local: > 16 threads and 10000000 iterations using ThreadLocals took 1532ms >
Using Date.setTime() instead of new Date() was a good idea, by the way. I added an implementation that uses a single ThreadLocal, and it is even faster. My numbers, at rev.786631: TimeDateElementBenchmarkTest_Sync: 5 threads and 10000000 iterations using Syncs took 9469ms TimeDateElementBenchmarkTest_Local: 5 threads and 10000000 iterations using ThreadLocals took 4672ms TimeDateElementBenchmarkTest_LocalStruct: 5 threads and 10000000 iterations using single ThreadLocal took 3609ms TimeDateElementBenchmarkTest_LocalStruct_SBuilder: 5 threads and 10000000 iterations using single ThreadLocal, with StringBuilder took 3594ms TimeDateElementBenchmarkTest_Sync: 16 threads and 10000000 iterations using Syncs took 32000ms TimeDateElementBenchmarkTest_Local: 16 threads and 10000000 iterations using ThreadLocals took 14500ms TimeDateElementBenchmarkTest_LocalStruct: 16 threads and 10000000 iterations using single ThreadLocal took 11312ms TimeDateElementBenchmarkTest_LocalStruct_SBuilder: 16 threads and 10000000 iterations using single ThreadLocal, with StringBuilder took 11360ms It is on WinXP, JRE 6u12, two cores (Centrino Duo), running from within an IDE. The last two lines of the four are implementations using StringBuffer vs. StringBuilder. The difference is negligible (either one or the other is "faster", on different runs). Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org