> I put a self-contained test up here:
> http://gist.github.com/452095
>
> To run it copy this to slurptest.clj and run these commands
> java clojure.main slurptest.clj makewords 100 (100 seems good for
> macs, 300 for linux)
>
> java -Xmx3G -Xms3G clojure.main slurptest.clj slurp|
> slurp2
>
> Trying either slurp or slurp2. I see big timing differences on both
> macs and linux machines but it would be interesting to see if other
> people do too.
Looking at core's slurp, the problem is that it reads one character at
a time from the reader. The underlying reader being buffered or not,
reading one character at a time is not good for performance. The
attached patch brings it back down do the speed of slurp2 (How do I
actually create a ticket on assembla? I couldn't find a way to do
that; just browse individual tickets. I can't change tickets either;
perhaps editing is not publicly allowed?).
Anyways, some performance for FreeBSD 8/x86-64 with:
openjdk6: 15 seconds slurp, 3.0 seconds slurp2
openjdk7 (fastdebug): 14.5 seconds slurp, 2.0 seconds slurp2
And slurp2 as a function of buffer size (single run each):
1: 17.8 seconds
128: 2.92 seconds
1024: 2.88 seconds
4096: 3.12 seconds
--
/ Peter Schuller
--
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
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index fdfd37a..fdffffc 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -5356,14 +5356,15 @@
{:added "1.0"}
([f & opts]
(let [opts (normalize-slurp-opts opts)
- sb (StringBuilder.)]
+ sb (StringBuilder.)
+ buffer (char-array 4096)]
(with-open [#^java.io.Reader r (apply jio/reader f opts)]
- (loop [c (.read r)]
+ (loop [c (.read r buffer)]
(if (neg? c)
(str sb)
(do
- (.append sb (char c))
- (recur (.read r)))))))))
+ (.append sb buffer 0 c)
+ (recur (.read r buffer)))))))))
(defn spit
"Opposite of slurp. Opens f with writer, writes content, then