lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2000-09-25-18:55:46 Bennett Todd:
> 2000-09-25-18:21:00 Sean Middleditch:
> > I haven't timed Lua and Ruby against each other for common
> > operations, but I've seen results in various "Language Comparison
> > Papers" around the web, and Ruby takes the lead in most of them.
> > I'm interested in what benchmark programs you used?
> 
> No benchmarks, just what I've read.

Well, I shoulda kept my mouth shut, got me again:-).

Tried to whip out the simplest trial I could find for basic
flow-of-control stuff, ruby beat out perl, although not too
horribly:-). ruby-1.6.0, perl 5.005_03, scripts appended, simple
count to a million by incrementing calling a subroutine to do the
increment, elapsed time(1) under Red Hat 6.2 on a P300 Mobile MMX w/
128MB RAM, doing very little else, best time of 3 trials (they had
very little variation in the runs):

	1.perl 7.16
	1.ruby 6.00

I tried to whomp it up in lua but I'm not a lua programmer, and Lua
4.0alpha (I've not been able to snag the 4.0beta yet) barfs on my
naive attempt. I'm so not a schemer that I didn't even attempt to
write it in qscheme. So much to do, so little time for play:-(.

-Bennett
#!/usr/bin/perl -w
use strict;

sub myincr { $_[0] + 1; }
my $x = 0;
for (my $i = 0; $i < 1000000; $i++) {
	$x = myincr($x);
}
print $x, "\n";
#!/usr/bin/ruby

def myincr(n)
	return n + 1
end

x = 0
for i in 1..1000000
	x = myincr(x)
end

print x, "\n"
#!/usr/bin/lua

function myincr(n)
	return n + 1
end

x = 0
i = 0
while i < 1000000 do
	x = myincr(x)
	i = i + 1
done

print x

Attachment: pgpzJFa99aNjZ.pgp
Description: PGP signature