Re: Non-OO interface to mysql
- From: "Peter J. Holzer" <hjp-usenet2@xxxxxx>
- Date: Mon, 22 Dec 2008 13:04:36 +0100
On 2008-12-21 23:31, Lars Eighner <usenet@xxxxxxxxxxxxxxx> wrote:
In our last episode, <qjr226xg7u.ln2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>, the
lovely and talented Keith Keller broadcast on comp.lang.perl.misc:
On 2008-12-21, Lars Eighner <usenet@xxxxxxxxxxxxxxx> wrote:
In our last episode,
<Itf3l.18820$iY3.12303@xxxxxxxxxxxx>,
the lovely and talented Tim Greer
broadcast on comp.lang.perl.misc:
However, I don't see a reason to seek such a thing out, just to avoid OO
(so I assume there's more to the question),
The idea is precisely to avoid OO (best) or at least to have function type
calls (second best).
What exactly do you hope to gain by avoiding OO?
1) The horrible slowness and waste of resources.
If you care about that, why are you coding in Perl? Compared to any
language that compiles to native code (even indirectly via a
JIT-compiler, like most Java implementations) it's horribly slow. And
compared to any language which uses an explicit type system, it's a
horrible waste of computer resources. (But it frees a lot of human
resources, and for a given time budget, the Perl programmer may even be
able to write a faster and less resource-intensive program than the C
programmer).
Now, let's do a little reality check on the "horrible slowness":
#!/usr/bin/perl
use warnings;
use strict;
use Benchmark 'cmpthese';
my $phandle = 23;
my $ohandle = MyClass->new();
my $arg = "this is an argument";
cmpthese(-3,
{
'proc' => sub { foo($phandle, $arg) },
'oo' => sub { $ohandle->foo($arg) },
});
sub foo {
my ($handle, $arg) = @_;
return $arg;
}
package MyClass;
sub new {
my ($class) = @_;
my $self = {};
return bless $self, $class;
}
sub foo {
my ($self, $arg) = @_;
return $arg;
}
__END__
This little program compares a "procedural" subroutine call with an
oo-style method call.
Rate oo proc
oo 783445/s -- -7%
proc 838852/s 7% --
Hooray, procedural calls are 7 percent faster. That's a whopping 84
nanoseconds per call. But let's run it again:
Rate proc oo
proc 786957/s -- -7%
oo 842802/s 7% --
Oh, this time oo is 7 percent faster.
If you repeat that a few times you will see that in about 50 % of the
cases the procedural call is slightly faster than the oo call and in
50 % of the cases the oo call is slightly faster - or in other words,
the difference is not even measurable with a simple benchmark.
hp
.
- Follow-Ups:
- Re: Non-OO interface to mysql
- From: C.DeRykus
- Re: Non-OO interface to mysql
- References:
- Non-OO interface to mysql
- From: Lars Eighner
- Re: Non-OO interface to mysql
- From: Tim Greer
- Re: Non-OO interface to mysql
- From: Lars Eighner
- Re: Non-OO interface to mysql
- From: Keith Keller
- Re: Non-OO interface to mysql
- From: Lars Eighner
- Non-OO interface to mysql
- Prev by Date: Re: confused a little by use strict
- Next by Date: Re: Non-OO interface to mysql
- Previous by thread: Re: Non-OO interface to mysql
- Next by thread: Re: Non-OO interface to mysql
- Index(es):
Relevant Pages
|