How are you running these tests? The "correct" way to benchmark such things is via a real benchmark framework (such as criterium) then compile your clojure app to a jar (perhaps via lein uberjar) and finally run it via a bare java invocation: java -jar my.jar.
Lein for example sometimes uses sub-par JVM settings, trading runtime performance for startup speed. Timothy On Sun, Mar 2, 2014 at 4:59 AM, Luc Prefontaine <lprefonta...@softaddicts.ca > wrote: > I cannot agree with this... > Not at 100% at least. > > String manipulations are frequent > enough to mandate some tuning > if the need is obvious. > > Looks to me that this is the case here. > > Other core fns went through rewrites > to improve performance. > > Simplicity has nothing to do with > internal implementations. > > If someone comes up with a better > implementation while providing > the same behaviours as the current > str fn, then it should make it's way > maybe in clojure.string. > > "fast-strings" ? Whatever it may be > named. > > Luc P. > > > Core fns should be simple, unsurprising, and general. > > > > 'Improving' str may hurt simplicity, make behavior more surprising and > > unexpected, and less general unless proven otherwise. > > > > On Sat, Mar 1, 2014 at 7:02 PM, bob <wee....@gmail.com> wrote: > > > > > > > > Good point, Thanks a lot. > > > > > > Shall we improve the str fn in the core lib? From my point of view, the > > > core fns should be performance sensitive. > > > > > > > > > > > > On Sunday, March 2, 2014 12:03:21 AM UTC+8, Shantanu Kumar wrote: > > >> > > >> > > >> > > >> On Saturday, 1 March 2014 15:32:41 UTC+5:30, bob wrote: > > >>> > > >>> Case : > > >>> > > >>> clojure verison: > > >>> > > >>> (time (dotimes [n 10000000] (str n "another word"))) ;; take about > > >>> 5000msec > > >>> > > >>> java version > > >>> > > >>> long time = System.nanoTime(); > > >>> > > >>> for(int i=0 ; i<10000000 ;i++){ > > >>> String a=i+"another word"; > > >>> } > > >>> System.out.println(System.nanoTime()-time); > > >>> > > >>> > > >>> The java version take about 500 msecs, I thought it might be caused > by > > >>> the str implementation which is using string builder, and it might > not be > > >>> the best choice in the case of no much string to concat, and then I > replace > > >>> "another word" with 5 long strings as the parameter, however no > surprise. > > >>> > > >>> I just wonder what make the difference, or how to find the > difference. > > >>> > > >> > > >> Others have added useful points to this thread. Java string > concatenation > > >> internally uses StringBuilder, so if you replace (str n "another > word") > > >> with the following: > > >> > > >> (let [sb (StringBuilder.)] > > >> (.append sb n) > > >> (.append sb "another word") > > >> (.toString sb)) > > >> > > >> ..then the perf improves 1/4 to 1/3. Further, with the following > tweak: > > >> > > >> (let [sb (StringBuilder. 20)] ; because StringBuilder allocates only > 16 > > >> chars by default on Oracle JRE > > >> (.append sb n) > > >> (.append sb "another word") > > >> (.toString sb)) > > >> > > >> ..the perf improves from 1/3 to less than 1/2. Here we simply avoid > > >> double allocation in StringBuilder. > > >> > > >> Other things I made sure were: > > >> > > >> 1. I used Criterium to measure > > >> 2. I used `-server` option > > >> 3. Made sure reflection warning was on > > >> > > >> Shantanu > > >> > > > -- > > > 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 > > > --- > > > You received this message because you are subscribed to the Google > Groups > > > "Clojure" group. > > > To unsubscribe from this group and stop receiving emails from it, send > an > > > email to clojure+unsubscr...@googlegroups.com. > > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > > > -- > > 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 > > --- > > You received this message because you are subscribed to the Google > Groups "Clojure" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to clojure+unsubscr...@googlegroups.com. > > For more options, visit https://groups.google.com/groups/opt_out. > > > -- > Luc Prefontaine<lprefonta...@softaddicts.ca> sent by ibisMail! > > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- "One of the main causes of the fall of the Roman Empire was that-lacking zero-they had no way to indicate successful termination of their C programs." (Robert Firth) -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.