in reply to Benchmarks target in Makefile

When I want to add targets to to the produced Makefile, I define the sub MY::postamble in Makefile.PL. You can see an example in https://github.com/pryrt/Math-PRBS/blob/master/Makefile.PL, where I add rules that clean up some of the files that make clean misses, or run a coverage report, or autogenerate my LICENSE and README.md from my main module's embedded POD. (As tobyink pointed out, make benchmarks is long... but maybe you could call the target make bm... er, wait, BM doesn't have the best connotations... ;-) Maybe make bench would be better.)

Replies are listed 'Best First'.
Re^2: Benchmarks target in Makefile
by bliako (Abbot) on Jun 19, 2018 at 15:11 UTC

    got it thanks!

    sub MY::postamble { return <<'POSTAMBLE'; bench :: benchmarks/*.b $(NOECHO) /usr/bin/env perl '$<' POSTAMBLE } WriteMakefile( INSTALL_BASE => blablabla )

    However, I tried to do this:

    sub MY::postamble { return <<'POSTAMBLE'; bench :: $(BENCHMARKS) $(NOECHO) /usr/bin/env perl '$<' POSTAMBLE } WriteMakefile( INSTALL_BASE => blablabla ... postamble => { BENCHMARKS => 'benchmarks/*.b' } );

    But I did not see any '$(BENCHMARKS)' var set in the Makefile. Is that the correct use of postamble you think?

      Based on my reading of ExtUtils::MakeMaker:

      postamble: Anything put here will be passed to MY::postamble() if you have one

      ... and the

      sub MY::postamble { my (undef,%h) = @_; ...
      start to my function that I linked earlier, I believe that MM passes the hash as args to the subroutine, not as variables in the Makefile, so I would suggest something like (untested):
      sub MY::postamble { my (undef,%h) = @_; my $ret = "bench :: $h{BENCHMARKS}\n"; $ret .= <<'POSTAMBLE'; $(NOECHO) /usr/bin/env perl '$<' POSTAMBLE return $ret; } WriteMakefile( INSTALL_BASE => blablabla ... postamble => { BENCHMARKS => 'benchmarks/*.b' } );

        thanks it works.

        Based on what you supplied, inserting into the Makefile a variable which holds all benchmark files $(BENCHMARKS), works this way:

        return "BENCHMARKS=$h{BENCHMARKS}\n" . <<'POSTAMBLE'; bench :: $(BENCHMARKS) $(NOECHO) /usr/bin/env perl '$<' POSTAMBLE
Re^2: Benchmarks target in Makefile
by bliako (Abbot) on Jun 19, 2018 at 23:52 UTC

    too quick to speak...

    It only runs the first benchmark of many.

    Secondly, perl must be given the path to blib to load the module because at the benchmark stage module is not installed.

    I have noticed in the Makefile that when they want to run multiple tests they do:

    PERL_DL_NONLAZY=1 $(FULLPERLRUN) "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" $(TEST_FILES)

    I did try the above with my benchmark files and works though I have to add Test::More directives into the benchmark file in order to keep it happy about not running any tests and also to be able to report the results of the benchmark

    sub MY::postamble { my (undef,%h) = @_; require Data::Dumper; #print STDERR Data::Dumper->Dump([\%h], [qw(mm_args{postamble})]); return "BENCHMARK_FILES=$h{BENCHMARK_FILES}\n" . <<'POSTAMBLE'; bench :: $(BENCHMARK_FILES) # PERL_DL_NONLAZY=1 $(FULLPERLRUN) $(BENCHMARK_FILES) PERL_DL_NONLAZY=1 $(FULLPERLRUN) "-MExtUtils::Command::MM" "-M +Test::Harness" "-e" "undef *Test::Harness::Switches; test_harness($(T +EST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" $(BENCHMARK_FILES) POSTAMBLE }

    I wonder if there is a way to do something similar for the multiple benchmark files.