From: Eric Hodel Date: 2003-02-27T12:14:16+09:00 Subject: Re: Ruby Compile-time optimization --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Daniel Carrera (dcarrera@math.umd.edu) wrote: > Now, as many of you know, Perl is not exactly an interpreted language. = =20 > Perl first "compiles" the program into some internal bytecode, which is= =20 > optimized before being run. For instance, if you have this: >=20 > use constant $MYCONST =3D> 3 > $val =3D 2 + $MYCONST >=20 > Perl turns it into: >=20 > $val =3D 5 >=20 > I ran the ruby code again, but this time I replaced 'val =3D 2 + 2' by 'v= al=20 > =3D 4' to simulate the effect of optimization. Again, the average of 3= =20 > tries: >=20 > Total Minus-the-loop > ruby 2.660 1.637 100.0% > ruby -optimized 1.793 0.770 47.0% > perl 1.770 0.630 38.5% >=20 > Now ther Perl's operation is only about 18% faster, which in this case=20 > particular case is mitigated by Ruby's loop being 11% faster. Overall,= =20 > the Perl code is only 1% faster (which is less than experimental error). >=20 > I realize that the fact that Ruby is a more dynamic language makes=20 > optimization more difficult, but I really think that we should look into= =20 > it. If you poke around in the mailing lists, you'll find it has been brought up before. In short, Fixnum#+ may be redefined at any time, so constant folding won't work. --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --Kj7319i9nmIyA2yE Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQE+XYKFMypVHHlsnwQRAueIAJ9RUNd3pcfQ0IM4vYpZYSiUsycOtgCgxHTX eGkM/X6HPrIMVgWeR0bPsFs= =Qivw -----END PGP SIGNATURE----- --Kj7319i9nmIyA2yE--