koeppea@foxi:~/perl_scripts> cat benchmark_constant.pl use strict; use Benchmark; my $startzeit = time; local $| = 1; sub test1 { system(qq{perl -e 'use constant NAME => "Alex";print STDERR NAME;' 2> /dev/null}); } sub test2 { system(qq{perl -e 'sub NAME {"Alex"};print STDERR NAME;' 2> /dev/null}); } sub test3 { use constant NAME1 => "Alex"; print STDERR NAME1; } sub test4 { sub NAME2 {"Alex"}; print STDERR NAME2; } timethese(1_000_000,{ "\nEinzeln Kompiliert und interpretiert (use constant): " => \&test1, "\nEinzeln Kompiliert und interpretiert (sub {} ): " => \&test2, "\nEinmal Kompiliert und einzeln interpretiert (use constant): " => \&test3, "\nEinmal Kompiliert und einzeln interpretiert (sub {} ): " => \&test4 }); print "\n===================================================================\n"; my $endzeit = time; printf ("Benchmark begann: %02d:%02d:%02d\n",reverse ((localtime($startzeit))[0..2])); printf ("Benchmark beendet: %02d:%02d:%02d\n",reverse ((localtime($endzeit))[0..2])); printf ("Benchmarkdauer: %02d:%02d:%02d\n",reverse ((localtime($endzeit - $startzeit))[0..2])); koeppea@foxi:~/perl_scripts> perl benchmark_constant.pl 2> /dev/null 1> benchmark_results.txt koeppea@foxi:~/perl_scripts> cat benchmark_results.txt Benchmark: timing 1000000 iterations of Einmal Kompiliert und einzeln interpretiert (sub {} ): , Einmal Kompiliert und einzeln interpretiert (use constant): , Einzeln Kompiliert und interpretiert (sub {} ): , Einzeln Kompiliert und interpretiert (use constant): ... Einmal Kompiliert und einzeln interpretiert (sub {} ): : 2 wallclock secs ( 2.22 usr + 0.34 sys = 2.56 CPU) @ 390625.00/s (n=1000000) Einmal Kompiliert und einzeln interpretiert (use constant): : 1 wallclock secs ( 0.76 usr + 0.23 sys = 0.99 CPU) @ 1010101.01/s (n=1000000) Einzeln Kompiliert und interpretiert (sub {} ): : 13282 wallclock secs (79.45 usr 687.58 sys + 6983.66 cusr 5386.81 csys = 13137.50 CPU) @ 1303.73/s (n=1000000) Einzeln Kompiliert und interpretiert (use constant): : 30559 wallclock secs (66.26 usr 643.40 sys + 22127.14 cusr 7380.62 csys = 30217.42 CPU) @ 1409.13/s (n=1000000) =================================================================== Benchmark begann: 09:51:01 Benchmark beendet: 22:01:53 Benchmarkdauer: 13:10:52 koeppea@foxi:~/perl_scripts>