I have some code that at one part will get executed a lot, and I'm wondernig which way is a more efficient implementation. I will use a for loop to simulate the part the gets executed alot:
option A:
my %sections = (
'somestring1' => 1,
'somestring2' => 1,
'somestring3' => 1,
'somestring4' => 1
);
for (0..10000)
{
# $element is chosen at random
$namespace = $element if $sections{$element};
}
option B:
for (0..10000)
{
# $element is chosen at random
$namespace = $element if ($element eq'somestring1' ||
$element eq'somestring2' ||
$element eq'somestring3' ||
$element eq'somestring4');
}
Can anyone benchmark this or know the answer as I am not familiar with benchmarking tools.
This code probably doesn't make sense in this context but it is in fact what I need to use.