If you use a compiled code - not an interpreted script
- Use Java 8 and the indy libraries and compiler
- Use the @CompileStatic annotation on your code, or on some of it. But you
could lose some of the advantages of the dynamic code
Two optimizations I have not seen mentioned so far; don't be so Groovy ;-)
1. Replace the the Map<> with an array of primitive ints. Why use an integer as
a key into a hash map when it can be used as an array index?
int[] results = new int[19] // since we need to index values 3..18
2.
On 29.03.2017 10:19, Paul Moore wrote:
On 28 March 2017 at 22:08, Nelson, Erick wrote:
Try this...
Thanks for the suggestion - there were some nice improvements in here.
def rng = new MersenneTwister()
def roll = {
rng.nextInt(6) + rng.nextInt(6) +
On 29 March 2017 at 15:34, Paul Moore wrote:
> So the big difference is removing def from roll, with removing def
> from rng having a smaller but detectable effect.
I just tried to generalise the script, by making a simulate function
that takes the action as a closure. I
On 29 March 2017 at 14:56, Nelson, Erick wrote:
> I'm not sure using or not using def would cause performance differences.
There definitely *seems* to be a difference.
def rng = new MersenneTwister()
def roll = {
rng.nextInt(6) + rng.nextInt(6) + rng.nextInt(6) +
I'm not sure using or not using def would cause performance differences.
It just affects variable scope.
http://mrhaki.blogspot.com/2009/11/groovy-goodness-variable-scope-in.html
Erick Nelson
Senior Developer
HD Supply, FM
Cell 858-740-6523
Home 760-930-0461
CONFIDENTIALITY NOTICE: This
On 28 March 2017 at 22:08, Nelson, Erick wrote:
> Try this...
Thanks for the suggestion - there were some nice improvements in here.
> def rng = new MersenneTwister()
>
> def roll = {
> rng.nextInt(6) + rng.nextInt(6) + rng.nextInt(6) + 3
> }
You changed my
This version runs around 0.10
@Grapes(
@Grab(group='org.apache.commons', module='commons-math3', version='3.6.1')
)
import org.apache.commons.math3.random.MersenneTwister
@groovy.transform.CompileStatic
class Benchmark {
int benchmark(Closure closure) {
def start =
Hi Paul,
The milliseconds to seconds conversion was off, so that puts the real time
at ~0.5 seconds.
> println "Took ${time/100} sec"
Using the following I get somewhere close to 0.15. Using an int array may
be worth it for higher values of N to avoid the boxing/unboxing of the ints.