#!/usr/bin/env perl use warnings; use strict; use Benchmark 'cmpthese'; my $lookup = join '', map{ chr( $_ / 255 * 100 ) } 0 .. 255; my $const = 100 / 255; cmpthese(-2, { lookup => sub { my @output = map { ord( substr $lookup, $_, 1 )} 0 .. 255; }, calc => sub { my @output = map {$_ / 255 * 100} 0 .. 255; }, calc2 => sub { my @output = map {$_ * $const} 0 .. 255; }, }); my @output1 = map { ord( substr $lookup, $_, 1 )} 0 .. 5; my @output2 = map {$_ * $const} 0 .. 5; print "@output1\n"; print "@output2\n"; __END__ # Results on my machine (v5.22.1 built for MSWin32-x64-multi-thread): Rate calc calc2 lookup calc 12009/s -- -24% -31% calc2 15753/s 31% -- -9% lookup 17376/s 45% 10% -- 0 0 0 1 1 1 0 0.392156862745098 0.784313725490196 1.17647058823529 1.56862745098039 1.96078431372549