M
Michele Dondi
While revising the benchmarks I had done for the fast random string
generation thread of a few weeks ago I wanted to include Abigail's
Inline::C solution too. Now, in the original ones I gave cmpthese() a
second param of the form:
{
...
Solution => \&Solution,
...
};
But this *doesn't* work[1] with the Inline::C solution, even if I
predeclare the sub. I've succeeded with
Inline => sub { Inline() },
and BTW it still largely outperforms all the other ones, but I'm
bothered by the fact that it involves one extra sub call which IMHO is
not elegant at all and, even if only marginally relevant, not fair for
comparison purposes. So, do you have any suggestion on what I should
do instead?
Also, the previous question was not terribly specific of Benchmark.pm
(but only of the kind of parameters one of its functions wants), so
more on-topic: is there any caveat with benchmarks carried on
Inline::C subs? I don't think so, but just to be sure...
As a side note, since I want to simply cmpthese() a bunch of (named)
subs giving as labels their respective names, I don't want to write
things twice as above and so was thinking of using a map() instead.
Now I'm unsure which of these would be better:
{ map { $_ => "$_()" } qw/sol1 sol2 .../ };
{ map {
no strict 'refs';
$_ => \&{$_};
} qw/sol1 sol2 .../ };
Generally speaking, I don't particularly like the 'code' version, and
I suspect it to be less efficient too[2]. (Well, I just tried: it is!)
Well, any advice?
[1] For some IMHO sensible acceptation of "doesn't work", in the sense
that I've tried some quite obvious variations, but then I'd be happy
to know that I was just too dumb and missed somethins obvious.
[2] Not that this is terribly relevant, but since we're speaking of
something that must be repeated *many* times, anyway...
Michele
generation thread of a few weeks ago I wanted to include Abigail's
Inline::C solution too. Now, in the original ones I gave cmpthese() a
second param of the form:
{
...
Solution => \&Solution,
...
};
But this *doesn't* work[1] with the Inline::C solution, even if I
predeclare the sub. I've succeeded with
Inline => sub { Inline() },
and BTW it still largely outperforms all the other ones, but I'm
bothered by the fact that it involves one extra sub call which IMHO is
not elegant at all and, even if only marginally relevant, not fair for
comparison purposes. So, do you have any suggestion on what I should
do instead?
Also, the previous question was not terribly specific of Benchmark.pm
(but only of the kind of parameters one of its functions wants), so
more on-topic: is there any caveat with benchmarks carried on
Inline::C subs? I don't think so, but just to be sure...
As a side note, since I want to simply cmpthese() a bunch of (named)
subs giving as labels their respective names, I don't want to write
things twice as above and so was thinking of using a map() instead.
Now I'm unsure which of these would be better:
{ map { $_ => "$_()" } qw/sol1 sol2 .../ };
{ map {
no strict 'refs';
$_ => \&{$_};
} qw/sol1 sol2 .../ };
Generally speaking, I don't particularly like the 'code' version, and
I suspect it to be less efficient too[2]. (Well, I just tried: it is!)
Well, any advice?
[1] For some IMHO sensible acceptation of "doesn't work", in the sense
that I've tried some quite obvious variations, but then I'd be happy
to know that I was just too dumb and missed somethins obvious.
[2] Not that this is terribly relevant, but since we're speaking of
something that must be repeated *many* times, anyway...
Michele