Re: Performance comparison Q
Stanislav Karchebny <[email protected]> Tue, 10 May 2005 10:18:58 +0300
| Newsgroups | gmane.comp.db.metakit |
|---|---|
| Organization | Skype |
| Message-ID | <[email protected]> |
On Monday 09 May 2005 18:49, Jean-Claude Wippler wrote:
> The C code is pretty obvious:
>
> int sum = 0; for (i = 0; i < 50000; ++i) sum += data[i];
>
> This one in tcl 8.4.6 runs at quite a bit under 1% of that speed:
>
> set sum 0; foreach x $data { incr sum $x }
>
> My question is: how would you write the above in <insert your
> language of choice here> ?
Ruby version (one way):
data = (0..49999) # similar to data = range(50000) in python.
data.inject(0) { |x,y| x += y }
or
sum = 0
data.each { |y| sum += y }
--
Best regards,
Stanislav Karchebny
Skype name: berkus
Get skype for free from www.skype.com
Information in this email is confidential and proprietary.
_____________________________________________
Metakit mailing list - [email protected]
http://www.equi4.com/mailman/listinfo/metakit
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQBCgGBi8v4MNv5cuDkRAtTrAJ9BvlQY06kUHFLhqWVkydemsU4vEQCcDlON ow3JfGgNhOi2sLwKfNIaK7Q= =5W3U -----END PGP SIGNATURE-----