[plt-scheme] Re: Using PLT Scheme libs elsewhere?

From: SpinyNorman (jmcaxolotl at gmail.com)
Date: Sun May 20 19:28:16 EDT 2007

On a 128MB file, using a chunk size of 32768, the Java version
completes in 12 sec.

real	0m12.349s
user	0m0.792s
sys	0m0.389s

Using mzscheme 369, invoked from a bash shell script, and the method
you propose, the scheme version completes in 26 sec.

real	0m25.812s
user	0m2.899s
sys	0m0.923s

Actually, the second run completes in 8 sec., presumably because the
library is now cached.

real	0m8.944s
user	0m0.977s
sys	0m0.364s

Previously, using mzscheme 360, and the scheme implementation of the
md5 library, the time was almost 6 min.

real	5m46.574s
user	1m21.794s
sys	0m4.231s


The Java version is a bit more verbose, so it spends a bit more
printing.  I *guess* that could partially account for why it is
slower.  (?!)


Is there a reason besides environment bloat why one should close
ports?  E.g., if mzscheme is invoked on a scheme module as in the bash-
script version suggested by Matthias, and then exits, are there any
bad effects of not explicitly closing a port?


I'm noticing that the headline for this sequence no longer suggests
what's in it:"Using PLT Scheme libs elsewhere?"  I don't suppose
there's a way to change it at this late date?


On May 18, 4:18 am, Jens Axel Søgaard <jensa... at soegaard.net> wrote:
> Hi,
>
> SpinyNorman wrote:
> >Share?  I'm flattered.  Here it is, and my only claim at this point is
> >that hey, it works.  Algorithmic insights are more than welcome.
>
> >(require (lib "md5.ss"))
>
> This md5.ss implements MD5 in Scheme. The Java MD5 is probably
> implemented in C.
> So if you switch to a C-based MD5 implementation, you'll get a speedup.
> Here is
> what to do:
>
> (require (planet "digest.ss" ("soegaard" "digest.plt" 1 2)))
> (require mzscheme)
>
> (define test-string (make-string 10000))
>
> (define (md-file-chunks port chunk-size)
>   (let loop ()
>     (begin
>       (display (md5 (read-bytes chunk-size port)))
>       (newline))
>     (if (not (eof-object? (peek-byte port)))
>     (loop))))
>
> (md-file-chunks (open-input-string test-string) 1024)
>
> See
> <http://planet.plt-scheme.org/display.ss?package=digest.plt&owner=soeg...>
> for documentation.
>
> This was tested on Windows, but ought to work elsewhere too.
> You'll need a relatively new version of PLT Scheme, for
> example 369.100.
>
> It wasn't obvious whether you put the md-file-chunks in a module or
> whether you are using the top-level. If you are using the top-level,
> the line
>
>     (require mzscheme)
>
> makes sure primitive operations are inlined.
>
> I'd love to hear your new timings.
>
> PS: Remember to close file ports after use.
>
> --
> Jens Axel Søgaard
>
> _________________________________________________
>   For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.