Hi,

I was experimenting with using mmap from clojure but I see vastly
different timings when compared to plain old Java and
MappedByteBuffer.

Here's my code and also represents the largest bit of clojure I have
written:

  (import '(java.io File))

  (use 'clojure.contrib.mmap)

  (def my-file (File. "/home/aim/largelog.bin"))

  (defn my-iterate-map [buf]
    (let [max (.remaining buf)]
      (loop [i (long 1)]
        (if (< i max)
          (do (.get buf)
              (recur (unchecked-inc i))))))
    buf)

  (time (my-iterate-map (mmap my-file)))

The results I see from clojure are:

  ;;;; (time (my-iterate-map (mmap my-file))) ...
  "Elapsed time: 113191.133057 msecs"

But If I do the same thing in Java I get:

  gone in 0.0540 seconds!

Is there something I can do to make the clojure version near or
equivalent to the java code below?

Thanks,
Andy.

--- Java code --

import java.io.File;
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
        public static void main(String[] args) throws Exception {
                File f = new File(args[0]);
                FileInputStream fis = new FileInputStream(f);
                ByteBuffer buf = 
fis.getChannel().map(FileChannel.MapMode.READ_ONLY,
0, f.length());
                long then = System.currentTimeMillis();
                long sum = 0;
                while (buf.hasRemaining()) {
                        sum += (buf.get() & 0xFF);
                }
                long now = System.currentTimeMillis();
                System.out.printf("gone in %.4f seconds!\n", (((now - then) /
1000.0)));
        }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to