Math n**m

Hi

10000.times { x=3 ** 3}
takes 10times longer than doing it with
... { x=3.1 ** 3 } # float or
...{ x= 3 * 3 * 3 }
Also with any variable for 3
How that???
I dont know what is calculated internally, but n.class==integer,
(**n) can be simplfied to for(i=0; i<n; i++) { x*=x } # C

Berg

Please show measurements and code. This is not true on my box:

irb(main):005:0> $r=1000_000
=> 1000000
irb(main):009:0> Benchmark.bmbm {|x| x.report("1"){$r.times{3 **
3}};x.report("2"){$r.times{3.1 ** 3}};x.report("3"){$r.times {3*3*3}}
}
Rehearsal -------------------------------------
1 0.094000 0.000000 0.094000 ( 0.098601)
2 0.171000 0.000000 0.171000 ( 0.166379)
3 0.063000 0.000000 0.063000 ( 0.069480)
---------------------------- total: 0.328000sec

        user system total real
1 0.063000 0.000000 0.063000 ( 0.075465)
2 0.171000 0.000000 0.171000 ( 0.167870)
3 0.078000 0.000000 0.078000 ( 0.070760)

Note the third code does not do a similar thing as the others.

If you put forward such claims you must provide the code that was used
to measure it if you want any serious discussion.

robert

···

On Tue, Apr 19, 2016 at 11:09 AM, A Berger <aberger7890@gmail.com> wrote:

10000.times { x=3 ** 3}
takes 10times longer than doing it with
... { x=3.1 ** 3 } # float or
...{ x= 3 * 3 * 3 }

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Yeah, running the same sort of benchmarks as Robert, I got the same sort of
numbers (relatively), back to 1.9.3p484 (which I keep around out of
historical interest.)

I also show pretty linear growth (dropping $r down by 10^2 drops the times
down by 10^2).

And if you rearrange the tests (e.g. 2,3,1) then 1 and 3 show the same sort
of numbers even in the rehearsal phase, while libraries and objects are
being initialised.

So I really don't know where the initial complaint comes from.

Cheers

···

On 20 April 2016 at 01:17, Robert Klemme <shortcutter@googlemail.com> wrote:

On Tue, Apr 19, 2016 at 11:09 AM, A Berger <aberger7890@gmail.com> wrote:

> 10000.times { x=3 ** 3}
> takes 10times longer than doing it with
> ... { x=3.1 ** 3 } # float or
> ...{ x= 3 * 3 * 3 }

Please show measurements and code. This is not true on my box:

irb(main):005:0> $r=1000_000
=> 1000000
irb(main):009:0> Benchmark.bmbm {|x| x.report("1"){$r.times{3 **
3}};x.report("2"){$r.times{3.1 ** 3}};x.report("3"){$r.times {3*3*3}}
}
Rehearsal -------------------------------------
1 0.094000 0.000000 0.094000 ( 0.098601)
2 0.171000 0.000000 0.171000 ( 0.166379)
3 0.063000 0.000000 0.063000 ( 0.069480)
---------------------------- total: 0.328000sec

        user system total real
1 0.063000 0.000000 0.063000 ( 0.075465)
2 0.171000 0.000000 0.171000 ( 0.167870)
3 0.078000 0.000000 0.078000 ( 0.070760)

Note the third code does not do a similar thing as the others.

If you put forward such claims you must provide the code that was used
to measure it if you want any serious discussion.

--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Hi
Same script
Rehearsal:
1 130
2 12
3 5
running on Ruboto (Java).
3**3 needs 10times of the other ones. As shown the implementation seems to
be very system-dependent (initiation: order of 1,2,3 makes no difference,
so its the calculation!)

Berg

Rehearsal is *not* the relevant part.

Also, the fact that you are not using MRI
(which one would assume unless stated otherwise)
should have been mentioned in your original post.
Different implementations might naturally behave
very differently.

Regards,
Marcus

···

Am 20.04.2016 um 19:42 schrieb A Berger:

Same script
Rehearsal:
1 130
2 12
3 5
running on Ruboto (Java).

​Ahh, yes, jruby (the backbone of Ruboto):

···

On 21 April 2016 at 03:42, A Berger <aberger7890@gmail.com> wrote:

running on Ruboto (Java).

~~~
$ cat test.rb
require 'benchmark'

$r = 1_000_000

Benchmark.bmbm do |x|
  x.report('1') { $r.times { 3 ** 3 }}
  x.report('2') { $r.times { 3.0 ** 3 }}
  x.report('3') { $r.times { 3 * 3 * 3 }}
end

$ jruby -v test.rb
jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa OpenJDK 64-Bit Server VM 24.95-b01
on 1.7.0_95-b00 +jit [linux-amd64]
Rehearsal -------------------------------------
1 0.610000 0.040000 0.650000 ( 0.349848)
2 0.120000 0.010000 0.130000 ( 0.103001)
3 0.070000 0.000000 0.070000 ( 0.047242)
---------------------------- total: 0.850000sec

        user system total real
1 0.180000 0.000000 0.180000 ( 0.177577)
2 0.090000 0.000000 0.090000 ( 0.087339)
3 0.020000 0.000000 0.020000 ( 0.022757)
$
~~~

I suggest filing a bug <https://github.com/jruby/jruby&gt; assuming it hasn't
been fixed since 9.0.4.0 (I'm currently installing 9.0.5.0 to see for
myself)

Cheers
--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Also, why don't you just copy and paste the whole output?

robert

···

On Wed, Apr 20, 2016 at 8:15 PM, stomar <sto.mar@web.de> wrote:

Am 20.04.2016 um 19:42 schrieb A Berger:

Same script
Rehearsal:
1 130
2 12
3 5
running on Ruboto (Java).

Rehearsal is *not* the relevant part.

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Same sort of numbers of 9.0.5.0, so yeah, feel free to log it.

Cheers

···

On 21 April 2016 at 07:40, Matthew Kerwin <matthew@kerwin.net.au> wrote:

I suggest filing a bug <https://github.com/jruby/jruby&gt; assuming it
hasn't been fixed since 9.0.4.0 (I'm currently installing 9.0.5.0 to see
for myself)

--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Ruboto is an Android thing. It's possible its output window isn't copyable.

···

On Wed, Apr 20, 2016 at 1:24 PM, Robert Klemme <shortcutter@googlemail.com> wrote:

On Wed, Apr 20, 2016 at 8:15 PM, stomar <sto.mar@web.de> wrote:
> Am 20.04.2016 um 19:42 schrieb A Berger:
>> Same script
>> Rehearsal:
>> 1 130
>> 2 12
>> 3 5
>> running on Ruboto (Java).
>
> Rehearsal is *not* the relevant part.

Also, why don't you just copy and paste the whole output?

For those playing along at home, m**n is fixed in jruby trunk: