What hardware are you running that on? Dual CPU might change things. Here's your code run on our test server (dual xeon Dell 1850).
[EMAIL PROTECTED] dim]$ java -version java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode) [EMAIL PROTECTED] dim]$ java RandomTest Testing with 1 threads for 5 seconds Generated 5,963,439 random ints using seed-many method Generated 51,890,734 random ints using seed-once method ==================== Testing with 5 threads for 5 seconds Generated 17,021,507 random ints using seed-many method Generated 11,540,379 random ints using seed-once method ==================== Testing with 10 threads for 5 seconds Generated 17,067,507 random ints using seed-many method Generated 12,153,002 random ints using seed-once method ==================== Testing with 25 threads for 5 seconds Generated 17,068,201 random ints using seed-many method Generated 12,252,194 random ints using seed-once method ==================== Testing with 50 threads for 5 seconds Generated 17,388,417 random ints using seed-many method Generated 11,822,572 random ints using seed-once method ==================== Mind you this changes a fair bit with JRockit: [EMAIL PROTECTED] dim]$ java -version java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) BEA JRockit(R) (build R26.4.0-63_CR302700-72606-1.5.0_06-20061127-1104-linux-ia32, ) [EMAIL PROTECTED] dim]$ java RandomTest Testing with 1 threads for 5 seconds Generated 6,521,686 random ints using seed-many method Generated 66,236,407 random ints using seed-once method ==================== Testing with 5 threads for 5 seconds Generated 7,964,427 random ints using seed-many method Generated 42,309,927 random ints using seed-once method ==================== Testing with 10 threads for 5 seconds Generated 7,966,630 random ints using seed-many method Generated 17,019,631 random ints using seed-once method ==================== Testing with 25 threads for 5 seconds Generated 6,153,009 random ints using seed-many method Generated 20,791,154 random ints using seed-once method ==================== Testing with 50 threads for 5 seconds Generated 15,619,450 random ints using seed-many method Generated 13,096,026 random ints using seed-once method ==================== I'm not sure if I'm prepared to draw any conclusions from this - my logic would suggest that more CPUs would mean less synchronization overhead, and hence better relative performance for seed-once, however the above shows better performance for seed-many.... what am I missing? cheers dim On 4/4/07, Ben Gunter <[EMAIL PROTECTED]> wrote: > As a follow-up to the lengthy conversation we had about java.util.Random > and whether it is best to reuse a single one and synchronize on it or > just create a new one each time, I wrote a program to compare the > performance of the two. Here are the results (CentOS 4.4, JDK 6): > > Testing with 1 threads for 5 seconds > Generated 1,191,083 random ints using seed-many method > Generated 24,562,853 random ints using seed-once method > ==================== > Testing with 5 threads for 5 seconds > Generated 1,736,231 random ints using seed-many method > Generated 11,417,596 random ints using seed-once method > ==================== > Testing with 10 threads for 5 seconds > Generated 1,749,759 random ints using seed-many method > Generated 10,706,179 random ints using seed-once method > ==================== > Testing with 25 threads for 5 seconds > Generated 1,727,634 random ints using seed-many method > Generated 10,922,547 random ints using seed-once method > ==================== > Testing with 50 threads for 5 seconds > Generated 1,732,329 random ints using seed-many method > Generated 10,734,163 random ints using seed-once method > ==================== > > The difference was less pronounced under Windows XP (JDK 6), but > seed-once still won: > > Testing with 1 threads for 5 seconds > Generated 2,335,585 random ints using seed-many method > Generated 45,853,345 random ints using seed-once method > ==================== > Testing with 5 threads for 5 seconds > Generated 3,290,170 random ints using seed-many method > Generated 6,214,038 random ints using seed-once method > ==================== > Testing with 10 threads for 5 seconds > Generated 3,283,141 random ints using seed-many method > Generated 6,706,248 random ints using seed-once method > ==================== > Testing with 25 threads for 5 seconds > Generated 3,258,902 random ints using seed-many method > Generated 6,597,599 random ints using seed-once method > ==================== > Testing with 50 threads for 5 seconds > Generated 3,244,338 random ints using seed-many method > Generated 6,650,498 random ints using seed-once method > ==================== > > The source code is attached. If I messed up anywhere, please let me know. > > -Ben > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Stripes-development mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/stripes-development > > > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Stripes-development mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/stripes-development
