decnartne has asked for the wisdom of the Perl Monks concerning the following question:
My configuration is as follows:#!/usr/bin/perl -w use strict; my $outf = "/tmp/outf.p.out"; open OUTF, ">$outf" or die "ERROR: could not open file $outf - $!\n"; foreach my $i ( 1..1000 ) { foreach my $j ( 0..255 ) { printf( OUTF "host DAAA%02X { blah blah XX:XX:XX:%02X; }\n", $ +j, $j ); printf( OUTF "host DAAA%02X { blah blah XX:XX:XX:%02X; }\n", $ +j, $j ); printf( OUTF "host DAAA%02X { blah blah XX:XX:XX:%02X; }\n", $ +j, $j ); printf( OUTF "host DAAA%02X { blah blah XX:XX:XX:%02X; }\n", $ +j, $j ); } } close OUTF; exit 0; __DATA__ /* C (somewhat?) equivalent of the perl script above */ #include <stdio.h> int main () { char *outf = "/tmp/outf.c.out"; FILE *fd; int i,j; if ( !( fd = fopen( outf, "w" ) ) ) { printf( "ERROR: could not open file %s\n", outf ); exit(1); } for ( i=1;i<=1000;i++ ) { for ( j=0;j<=255;j++ ) { fprintf( fd, " host DAAA%02X { blah blah XX:XX:XX:%02X; +}\n", j, j ); fprintf( fd, " host DAAA%02X { blah blah XX:XX:XX:%02X; +}\n", j, j ); fprintf( fd, " host DAAA%02X { blah blah XX:XX:XX:%02X; +}\n", j, j ); fprintf( fd, " host DAAA%02X { blah blah XX:XX:XX:%02X; +}\n", j, j ); } } fclose( fd ); exit(0); }
hostname% uname -a SunOS hostname 5.9 Generic_117171-07 sun4u sparc SUNW,Sun-Fire-V440 hostname% perl -v This is perl, v5.6.1 built for sun4-solaris-64intTimed results are:
hostname% time ../bin/ftest 1.0u 0.0s 0:01 85% 0+0k 0+0io 0pf+0w hostname% time ./ftest.pl 4.0u 0.0s 0:04 86% 0+0k 0+0io 0pf+0w(... for the curious, I have ported a C program which generates our DHCP table to perl, thus the pseudo formatting of the string...)
decnartne ~ entranced
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl printf vs C fprintf performance
by moot (Chaplain) on Mar 14, 2005 at 19:59 UTC | |
by decnartne (Beadle) on Mar 14, 2005 at 20:05 UTC | |
|
Re: perl printf vs C fprintf performance
by brian_d_foy (Abbot) on Mar 14, 2005 at 20:07 UTC | |
by decnartne (Beadle) on Mar 14, 2005 at 20:11 UTC | |
|
Re: perl printf vs C fprintf performance
by hv (Prior) on Mar 15, 2005 at 01:22 UTC | |
by decnartne (Beadle) on Mar 15, 2005 at 14:23 UTC | |
by Leotrillo (Initiate) on Nov 02, 2009 at 21:58 UTC | |
by Anonymous Monk on Nov 03, 2009 at 04:32 UTC | |
|
Re: perl printf vs C fprintf performance
by sh1tn (Priest) on Mar 14, 2005 at 21:54 UTC |