From: Eric Hodel Date: 2002-12-14T08:31:18+09:00 Subject: Re: Ruby slow?? --Bn2rw/3z4jIqBvZU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Garriss, Michael (Michael.Garriss@abacus-direct.com) wrote: > Found this site about how languages stack up against each other. This te= st > put Ruby far behind to others. Has this changed with 1.7? What's the de= al > with these results? >=20 > http://www.bagley.org/~doug/shootout/bench/prodcons/ This is one of the 'same way' tests, for the same problem, I'd rather use Queue, which judging from the comparitive speed of my machine, brings ruby right in there around python. Note that what this test is really testing is the speed of the lock/unlock of the Mutex, thread switching, and the CV. Reading Alternates, there is a Python example that uses a Queue too. code: #!/usr/local/bin/ruby require 'thread' def main(n) q =3D Queue.new # shared consumed =3D produced =3D 0 consumer =3D Thread.new do i =3D 0=20 until i =3D=3D n do i =3D q.pop consumed +=3D 1=20 end end producer =3D Thread.new do 1.upto(n) do |i| q.push(i) produced +=3D 1=20 end end producer.join consumer.join puts "#{produced} #{consumed}" end main(Integer(ARGV.shift || 1)) # end code $ time ruby prodcon-queue.rb 100000=20 100000 100000 real 0m41.863s user 0m38.061s sys 0m0.235s $ time ruby prodcon-bagley.rb 100000 100000 100000 real 1m56.206s user 1m41.711s sys 0m0.742s --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --Bn2rw/3z4jIqBvZU Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (FreeBSD) iD8DBQE9+m3EMypVHHlsnwQRApGNAKDNr9FIxSYH6tMx0QZD6eRh9uW/AgCgzLDa blJhLHklODHvoRuOKP+dYCc= =xmZA -----END PGP SIGNATURE----- --Bn2rw/3z4jIqBvZU--