From: ptkwt@... (Phil Tomson) Date: 2003-09-23T05:31:16+09:00 Subject: Re: Performance: Ruby vs Java In article <3f6e50b5$0$48907$edfadb0f@dtext02.news.tele.dk>, Thomas Sondergaard wrote: >The difference is that ruby is interpreted and has a dynamic nature that >makes it difficult to optimize (or so I understand), while java is jitted >and for this single non-OO example it is probably as fast as C. > >I can't resist the temptation of plugging my own project rubydotnet, which >allows you to implement such performance critical code in a .net language. > >CS_SCRIPT = <<-EOF > int n = (int) args[0]; > for (int i=0; i for (int j=0; j if (j*i == n) > return false; > return true; > EOF > >def isPrime(n) > cs_eval(CS_SCRIPT, n) >end > >puts isPrime(2) >puts isPrime(4) >puts isPrime(7) >puts isPrime(25) >puts isPrime(400003) > >On my laptop (3ghz P4): >$ time ruby prime.rb >true >false >true >false >false > >real 0m0.666s >user 0m0.015s >sys 0m0.000s > Or, for those of us not on a .NET platform (Windows) or those of us who are wary of it... You could do something very similar using Ryan Davis' RubyInline package. http://sourceforge.net/projects/rubyinline/ Phil