[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Benchmark
- From: Ken Rawlings <krawling@...>
- Date: Thu, 2 Sep 1999 21:00:02 -0500 (EST)
Steve,
Sure, Here you go. The Python code might complain about being cut and
pasted -- if you can't get it up and running, let me know and i'll
throw it up on a website or something.
_Ken
----Perl-------
sub pnpoly {
local($npol, $xxp, $yyp, $x, $y);
($npol, $xxp, $yyp, $x, $y) = @_;
local($i, $j, $c = 0, @yp = @$yyp, @xp = @$xxp);
$j = $npol-1;
for ($i = 0; $i < $npol; $i++) {
if (((($yp[$i] <= $y) && ($y < $yp[$j])) ||
(($yp[$j] <= $y) && ($y < $yp[$i]))) && ($x < (($xp[$j] -
$xp[$i]) * ($y - $yp[$i]) / ($yp[$j] - $yp[$i]) + $xp[$i]))) { $c
= !$c;}
$j = $i
}
$c;
}
sub polytest {
local($npol, $count, @xp, @yp);
$npol=20;
$count=0;
@xp = (0.0,1.0,1.0,0.0,0.0,1.0,-.5,-1.0,-1.0,-2.0,
-2.5,-2.0,-1.5,-.5,1.0,1.0,0.0,-.5,-1.0,-.5);
@yp = (0.0,0.0,1.0,1.0,2.0,3.0,2.0,3.0,0.0,-.5,
-1.0,-1.5,-2.0,-2.0,-1.5,-1.0,-.5,-1.0,-1.0,-.5);
for($ii = 0; $ii < 50000; $ii++) {
if (pnpoly($npol,\@xp,\@yp,0.5,0.5)) {$count++};
if (pnpoly($npol,\@xp,\@yp,0.5,1.5)) {$count++};
if (pnpoly($npol,\@xp,\@yp,-.5,1.5)) {$count++};
if (pnpoly($npol,\@xp,\@yp,0.75,2.25)) {$count++};
if (pnpoly($npol,\@xp,\@yp,0,2.01)) {$count++};
if (pnpoly($npol,\@xp,\@yp,-.5,2.5)) {$count++};
if (pnpoly($npol,\@xp,\@yp,-1.0,-.5)) {$count++};
if (pnpoly($npol,\@xp,\@yp,-1.5,.5)) {$count++};
if (pnpoly($npol,\@xp,\@yp,-2.25,-1.0)) {$count++};
if (pnpoly($npol,\@xp,\@yp,0.5,-.25)) {$count++};
if (pnpoly($npol,\@xp,\@yp,0.5,-1.25)) {$count++};
if (pnpoly($npol,\@xp,\@yp,-.5,-2.5)) {$count++};
}
print "\n count ", $count, "\n";
}
polytest
----Python-----
def pnpoly(npol, xp, yp, x, y):
c = 0
i=0
j=npol-1
while i < npol:
if ((((yp[i]<=y) and (y<yp[j])) or ((yp[j]<=y) and
(y<yp[i]))) and (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) +
xp[i])):
c = not(c)
j = i
i = i+1
return c
def pnpolytest():
npol=20
count=0
xp=
[0.0,1.0,1.0,0.0,0.0,1.0,-.5,-1.0,-1.0,-2.0,-2.5,-2.0,-1.5,-.5,1.0,1.0,0.0,-.5,-1.0,-.5]
yp=
[0.0,0.0,1.0,1.0,2.0,3.0,2.0,3.0,0.0,-.5,-1.0,-1.5,-2.0,-2.0,-1.5,-1.0,-.5,-1.0,-1.0,-.5]
i=0
while i < 50000:
if (pnpoly(npol,xp,yp,0.5,0.5)): count=count+1
if (pnpoly(npol,xp,yp,0.5,1.5)): count=count+1
if (pnpoly(npol,xp,yp,-.5,1.5)): count=count+1
if (pnpoly(npol,xp,yp,0.75,2.25)): count=count+1
if (pnpoly(npol,xp,yp,0,2.01)): count=count+1
if (pnpoly(npol,xp,yp,-.5,2.5)): count=count+1
if (pnpoly(npol,xp,yp,-1.0,-.5)): count=count+1
if (pnpoly(npol,xp,yp,-1.5,.5)): count=count+1
if (pnpoly(npol,xp,yp,-2.25,-1.0)): count=count+1
if (pnpoly(npol,xp,yp,0.5,-.25)): count=count+1
if (pnpoly(npol,xp,yp,0.5,-1.25)): count=count+1
if (pnpoly(npol,xp,yp,-.5,-2.5)): count=count+1
i=i+1
print 'count '+ `count`
pnpolytest()
-----------
On Mon, 30 Aug 1999, Steve Dekorte wrote:
> Ken Rawlings <krawling@shooter.bluemarble.net> wrote:
> > Since there seems to be quite a bit of interest in Lua benchmarks,
> > here's my results from a multi-language numeric benchmark I ran a
> > while back to get a general feel for the speed of several languages.
> >
> > In each case nothing special was done for optimization, either in
> > the language or in the compiler settings. Take the benchmark with
> > a large grain of salt -- it's by no means comprehensive.
> >
> > (PII300, NT4.0):
> >
> > Language Seconds
> > ------------------- -------
> > C [MSVC 5.0] 1.5
> > Java 1.2.1 (Classic) 1.2
> > Java 1.1.6 44.1
> > Lua 3.1 65.8
> > Perl 5.005 202.8
> > Python 1.5.2 91.2
> > TCL 8.1 205.6
> > TCL 8.0.5 392.9
> >
> > _Ken
>
> Ken,
>
> Could you send me the Python and Perl code for this benchmark?
>
> Steve
>
>