[Top][All Lists]

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

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

From: Elf
Subject: Re: [Chicken-users] Good way to code the equivalent to this?
Date: Mon, 25 Aug 2008 06:19:22 -0700 (PDT)

i got almost the same time as with my previous (incorrect) method by using a single hash table and an alist instead of a hash for the inner structure. memory usage isnt so good though. :(

using a sparse multiple-alist structure seems to work nicely in small space
and good time.  i can post the code if interested.


On Sun, 24 Aug 2008, Jim Ursetto wrote:

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";
foreach $n (0 .. 10000) {
$x = int(rand(500000));
$y = int(rand(500000));
if (exists $a{$x} and $a{$x} == $y) {  # quell warning on undef

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
       (let loop ((i   0)
                  (r   '()))
           (if (fx= 250000 i)
               (loop (fx+ 1 i)
                     (cons (cons (random 500000) (random 500000)) r))))

reply via email to

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