On Thu, 18 May 2000, Autarch wrote:
> C seems like serious overkill for something to simply generate plain text
> output. How slow is making a string in perl compared to doing it in C?
> I can't imagine there's to much of a difference.
more like Perl is serious overkill :)
SV's are BIG, notice the $unused variable and the B::TerseSize output
(from Apache::Status) below, even before a string is copied into it,
there's 48 bytes eaten.
my $r = shift;
$r->send_http_header;
my $unused;
my $string = "hi";
print $string;
============================================================
Totals: 1455 bytes | 23 OPs
============================================================
PADLIST summary:
0: undef [AV 116 bytes] MAX => 3
1: $r [RV 52 bytes] 0x891b9b4
2: undef [GV 81 bytes]
3: undef [NULL 24 bytes] 0x891ba44
4: undef [NULL 24 bytes] 0x891ba5c
5: $unused [NULL 48 bytes] 0x891ba50
6: $string [PV 63 bytes] hi
now let's look at CGI::start_html:
============================================================
Totals: 15595 bytes | 330 OPs
============================================================
PADLIST summary:
8: $title [PV 78 bytes] Untitled Document
35: undef [PV 140 bytes] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
40: undef [PV 56 bytes] <HTML><HEAD><TITLE>
46: undef [PV 81 bytes] <HTML><HEAD><TITLE>Untitled
Document</TITLE>
48: undef [PV 65 bytes] <LINK REV=MADE HREF="mailto:
59: undef [PV 49 bytes] <BASE HREF="
77: undef [PV 48 bytes] <NOSCRIPT>
94: undef [PV 49 bytes] </HEAD><BODY
96: undef [PV 50 bytes] </HEAD><BODY>
100: undef [PV 45 bytes] </TITLE>
101: undef [PV 199 bytes] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><TITLE>Untitled Document</TITLE>
</HEAD><BODY>
i've omitted all but the string variables, notice the additional copies,
which are a result of concatination. Perl copies *everything* and these
copies add up to alot. this is why i would like to see an html
generator written in c, it would result in a much smaller footprint, no
matter what the Perl implementation may be.