From: Charles Oliver Nutter on
On Tue, Jul 20, 2010 at 8:32 AM, Colin Bartlett <colinb2r(a)googlemail.com> wrote:
> jruby 1.5.0.RC1 (ruby 1.8.7 patchlevel 249) (2010-04-14 0b08bc7)
>  (Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]
> owtdi      1.980000   0.000000   1.980000 (  1.979000)
> tmtowtdi   1.523000   0.000000   1.523000 (  1.522000)
> I ought to point out that in a subsequent JRuby run
>  owtdi user = 1.625 and tmtowtdi user = 1.809,
>  and in another run owtdi user = 2.118 and tmtowtdi user = 1.987,
> so quite variable! But there was quite a lot of apparently random and
> purposeless disk i/o going on while the benchmarks were running. (Thank you,
> Windows Vista!) So I would place even less reliance than usual on these
> benchmarks. But using inject does seem significantly slower, especially so
> using 1.8.6.

I know this isn't what the original post was about...but...

The variability is probably due partially to the jitting behavior of
the JVM; it's hard to know when the JVM will hit its stable state.

FWIW, a longer run will get even faster, and passing --server to JRuby
boosts it too:

jruby Java 6 server, fifth iteration:
user system total real
owtdi 0.223000 0.000000 0.223000 ( 0.223000)
tmtowtdi 0.223000 0.000000 0.223000 ( 0.223000)

ruby 1.9.2 trunkish:
user system total real
owtdi 0.470000 0.010000 0.480000 ( 0.481433)
tmtowtdi 0.350000 0.000000 0.350000 ( 0.350423)

I don't have an explanation for the performance difference; the logic
involved should be pretty native-lib heavy.

- Charlie

From: David Masover on
On Tuesday, July 20, 2010 10:05:27 am Rob Biedenharn wrote:
> On Jul 20, 2010, at 10:58 AM, Vitaliy Yanchuk wrote:
> > Jean-Julien Fleck wrote:
> >> 2010/7/20 Vitaliy Yanchuk <fuksito(a)gmail.com>:
> >>> Jean-Julien Fleck, thanks.
> >>> Maybe have an idea of a one-line version? :)
> >>
> >> Well: quite the same using inject:
> >>
> >> arr.inject(Hash.new(0)) {|h,e| h[e]+= 1; h}
> >>
> >> It all depends on what you call 'one-line' :o)
> >>
> >> Cheers,
> >
> > Wow, Inject is cool method, thanks !
> > In my mind one-line is that dows not have semi-coloms or new lines of
> > course
>
> Soo... that has a semi-colon and isn't then a one-liner?? ;-)

If that really bothers anyone...

Hash.new(0).tap{|h| arr.each{|e| h[e] += 1} }

From: Michel Demazure on
David Masover wrote:
>
> Hash.new(0).tap{|h| arr.each{|e| h[e] += 1} }

Yes ! I always use this construct. Instead of

obj = Klass.new
# do something to obj
obj

I use

Klass.new do |obj|
# do something to obj
end

which, at least to me, has a better look.

_md

--
Posted via http://www.ruby-forum.com/.