chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Good way to code the equivalent to this?


From: Jim Ursetto
Subject: Re: [Chicken-users] Good way to code the equivalent to this?
Date: Sun, 24 Aug 2008 16:12:21 -0500

Note that your solution effects a mapping of x -> y, not from x -> y
-> #t.  That gets the job accomplished correctly, but doesn't reflect
the original Perl code.  For a fair comparison, you have to change the
perl code to match, and then it runs in 1/3 of the memory and 1/2 the
time of the original perl code.

This is what I mean concretely:

print "Filling the array with 250000 entries.\n";
foreach $n (0 .. 250000) {
 $x = int(rand(500000));
 $y = int(rand(500000));
 $a{$x} = $y;                     # change to one-level hash
}

print "Reading from the array 10000 times\n";
$hits=0;
foreach $n (0 .. 10000) {
 $x = int(rand(500000));
 $y = int(rand(500000));
 if (exists $a{$x} and $a{$x} == $y) {  # quell warning on undef
   $hits++;
 }
}

print "Done (hits $hits)\n";

On Sun, Aug 24, 2008 at 5:56 AM, Elf <address@hidden> wrote:
>
> for an improvement in time (surprisingly), use
>
> (define a
>    (alist->hash-table
>        (let loop ((i   0)
>                   (r   '()))
>            (if (fx= 250000 i)
>                r
>                (loop (fx+ 1 i)
>                      (cons (cons (random 500000) (random 500000)) r))))
>        =))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]