perldoc.t 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #! /usr/bin/env perl
  2. # brian d foy: "Compiled perlpod should be faster then uncompiled"
  3. use Test::More;
  4. use strict;
  5. BEGIN {
  6. unshift @INC, 't';
  7. require "test.pl";
  8. }
  9. use Config;
  10. use File::Spec;
  11. use Time::HiRes qw(gettimeofday tv_interval);
  12. my $X = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  13. my $perldoc = File::Spec->catfile($Config{installbin}, 'perldoc');
  14. my $perlcc = $] < 5.008
  15. ? "$X -Iblib/arch -Iblib/lib blib/script/perlcc -uFile::Spec -uIO::Handle"
  16. : "$X -Mblib blib/script/perlcc -uFile::Spec -uIO::Handle";
  17. my $exe = $Config{exe_ext};
  18. my $perldocexe = "perldoc$exe";
  19. # XXX bother File::Which?
  20. die "1..1 # $perldoc not found\n" unless -f $perldoc;
  21. plan tests => 7;
  22. my $res = `$perlcc -o perldoc$exe $perldoc`;
  23. ok(-s $perldocexe, "$perldocexe compiled");
  24. my $t0 = [gettimeofday];
  25. my $ori = `$X -S $perldoc -T -f wait`;
  26. my $t1 = tv_interval( $t0, [gettimeofday]);
  27. $t0 = [gettimeofday];
  28. my $cc = `./perldoc -T -f wait`;
  29. my $t2 = tv_interval( $t0, [gettimeofday]);
  30. TODO: {
  31. # old perldoc 3.14_04-3.15_04: Can't locate object method "can" via package "Pod::Perldoc" at /usr/local/lib/perl5/5.14.1/Pod/Perldoc/GetOptsOO.pm line 34
  32. # dev perldoc 3.15_13: Can't locate object method "_is_mandoc" via package "Pod::Perldoc::ToMan"
  33. local $TODO = "compiled does not print yet" if $] >= 5.010;
  34. is($cc, $ori, "same result");
  35. }
  36. ok($t2 < $t1, "compiled faster than uncompiled: $t2 < $t1");
  37. $res = `$perlcc -Wb=-O2 -o perldoc_O2$exe $perldoc`;
  38. ok(-s "perldoc_O2$exe", "perldoc compiled");
  39. $t0 = [gettimeofday];
  40. $cc = $^O eq 'MSWin32' ? `perldoc$exe -T -f wait` : `./perldoc -T -f wait`;
  41. my $t3 = tv_interval( $t0, [gettimeofday]);
  42. TODO: {
  43. local $TODO = "compiled does not print yet" if $] >= 5.010;
  44. is($cc, $ori, "same result");
  45. }
  46. TODO: {
  47. local $TODO = "slow compiled -O2";
  48. ok($t3 <= $t2, "compiled -O2 not slower than -O0: $t3 <= $t2");
  49. ok($t3 < $t1, "compiled -O2 faster than uncompiled: $t3 < $t1");
  50. }
  51. END {
  52. unlink $perldocexe if -e $perldocexe;
  53. unlink "perldoc_O2$exe" if -e "perldoc_O2$exe";
  54. }