Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Does it take around 15 seconds to do anything 160000 times for you? Benchmark it on your system just returning x; it may well be that the hypot operation ( implemented in C ) is negligible than the interpreter overhead.</p> <p>For ruby 1.8.7 with khell's memoized get method, calling the function inside a get method, and just returning x inside a get method, with 100000 iterations:</p> <pre> peregrino:$ time ruby src/memoized_hypot.rb real 0m1.714s user 0m1.436s sys 0m0.080s peregrino:$ time ruby src/plain_hypot.rb real 0m0.495s user 0m0.364s sys 0m0.060s peregrino:$ time ruby src/empty_hypo.rb real 0m0.369s user 0m0.220s sys 0m0.068s </pre> <p>kheill's memoization creates a string on every call, which is much more costly than calling the C library's hypot function on every call. </p> <p>The difference between the calling hypot and just returning x indicates that hypot is only contributing 25% of the runtime. It's not the code you should be optimising - instead try inlining the call to the library if you can rather than wrapping it in another method.</p> <pre> peregrino:$ time ruby src/inline_hypot.rb real 0m0.365s user 0m0.236s sys 0m0.044s </pre> <p>which is </p> <pre><code>100000.times{ |i| Math.hypot(i,6) } </code></pre> <p>rather than</p> <pre><code>100000.times{ |i| foo.get(i,6) } </code></pre> <p>where foo is an object with the methods posted.</p> <hr> <p>These times were on a netbook ( Asus eeepc 900 ) which isn't massively speedy, so it's a bit odd that they are much faster than your times. So something else might be dominating your results. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload