
$N = shift || 1024*768;
print "$N trials:\n";

sub cmyk {
	  my ($r, $g, $b) = @_;
	  my ($c, $m, $y) = (1-$r, 1-$g, 1-$b);
	  my $k = $c < $m ? ($c < $y ? $c : $y)
	                  : ($m < $y ? $m : $y);  # Minimum
	  for ($c, $m, $y) { $_ -= $k }
	  [$c, $m, $y, $k];	
	}
sub null {
}

my %cache;
sub cmyk_cache {
	  my ($r, $g, $b) = @_;
	  return $cache{$r,$g,$b} if exists $cache{$r,$g,$b};
	  my ($c, $m, $y) = (1-$r, 1-$g, 1-$b);
	  my $k = $c < $m ? ($c < $y ? $c : $y)
	                  : ($m < $y ? $m : $y);  # Minimum
	  for ($c, $m, $y) { $_ -= $k }
	  $cache{$r,$g,$b} = [$c, $m, $y, $k];	
	}

$LABEL = 'Null loop';
($us, $ss) = times;
for ($i = 0; $i < $N; $i++) 
{
}
($ue, $se) = times;
printf "$LABEL:\t%.2f %.2f %.2f\n", $ue-$us, $se-$ss, $ue+$se-$us-$ss;

$LABEL = 'CMYK fixed';
($us, $ss) = times;
for ($i = 0; $i < $N; $i++) 
{
  cmyk(128, 128, 128);
}
($ue, $se) = times;
printf "$LABEL:\t%.2f %.2f %.2f\n", $ue-$us, $se-$ss, $ue+$se-$us-$ss;

$LABEL = 'CMYK varying';
($us, $ss) = times;
for ($i = 0; $i < $N; $i++) 
{
  my $j = $i & 255;
  cmyk($j,$j,$j);
}
($ue, $se) = times;
printf "$LABEL:\t%.2f %.2f %.2f\n", $ue-$us, $se-$ss, $ue+$se-$us-$ss;

$LABEL = 'null func';
($us, $ss) = times;
for ($i = 0; $i < $N; $i++) 
{
  my $j = $i & 255;
  null($j,$j,$j);
}
($ue, $se) = times;
printf "$LABEL:\t%.2f %.2f %.2f\n", $ue-$us, $se-$ss, $ue+$se-$us-$ss;

$LABEL = 'CMYK cached';
($us, $ss) = times;
for ($i = 0; $i < $N; $i++) 
{
  my $j = $i & 255;
  cmyk_cache($j,$j,$j);
}
($ue, $se) = times;
printf "$LABEL:\t%.2f %.2f %.2f\n", $ue-$us, $se-$ss, $ue+$se-$us-$ss;







