in reply to Re^2: A small Deity AI class system
in thread A small Deity AI class system

I really encourage you to Benchmark instead of assuming. You will get surprises somewhat often. And assuming a simple arithmetic op is a performance killer seems silly. It took 10 million iterations to even be able to get this to benchmark without complaining it wasn't enough to be sure; and while a fifteenth of a millionth of a second is indeed three times faster than a fifth of a millionth of a second… does it actually matter on any level for the application in question?

moo@cow[483]~>perl pm-dice use strictures; use Benchmark "cmpthese"; sub d10 { my $self = shift; return rand(10); } sub d10_2 { rand(10) } sub d10_3 { 1 + int( rand(10) ) } sub d10_4 { 1 + rand(10) } cmpthese( 10_000_000, { orig => \&d10, orig_simple => \&d10_2, int_plus_one => \&d10_3, plus_one => \&d10_4, }); __END__ Rate orig int_plus_one plus_one orig_si +mple orig 4048583/s -- -19% -38% + -74% int_plus_one 5000000/s 24% -- -24% + -68% plus_one 6578947/s 62% 32% -- + -59% orig_simple 15873016/s 292% 217% 141% + --