f191ab2004-07-08Henrik Grubbström (Grubba) // $Id: benchmark.pike,v 1.7 2004/07/08 15:36:42 grubba Exp $
0d03312003-08-24Martin Nilsson  #pike __REAL_VERSION__
284c2a2002-12-06Martin Nilsson 
6148162002-12-14Martin Nilsson constant description = "Runs some built in Pike benchmarks.";
284c2a2002-12-06Martin Nilsson constant help = #" Benchmarks Pike with %d built in benchmark tests. Arguments: -h, --help Shows this help text. -m<number>, --max-runs=<number> Runs a test at most <number> of times. Defaults to 25. -s<number>, --max-seconds=<number> Runs a test at most <number> of seconds, rounded up to the closest complete test. Defaults to 5.
2c52e42002-12-17Per Hedbor 
4d8f242003-07-30Martin Stjernholm -t<glob>[,<glob>...], --tests=<glob>[,<glob>...]
2c52e42002-12-17Per Hedbor  Only run the specified tests.
284c2a2002-12-06Martin Nilsson ";
a3b12a2003-01-19Martin Nilsson int(0..) main(int num, array(string) args)
284c2a2002-12-06Martin Nilsson { mapping(string:Tools.Shoot.Test) tests=([]); array results=({});
f191ab2004-07-08Henrik Grubbström (Grubba)  foreach (indices(Tools.Shoot),string test)
284c2a2002-12-06Martin Nilsson  { program p; Tools.Shoot.Test t; if ((programp(p=Tools.Shoot[test])) && (t=p())->perform) tests[test]=t; } int seconds_per_test = 5; int maximum_runs = 25;
4d8f242003-07-30Martin Stjernholm  array(string) test_globs = ({"*"});
284c2a2002-12-06Martin Nilsson 
2c52e42002-12-17Per Hedbor  foreach(Getopt.find_all_options(args, ({ ({ "help", Getopt.NO_ARG, "-h,--help"/"," }), ({ "maxrun", Getopt.HAS_ARG, "-m,--max-runs"/"," }), ({ "maxsec", Getopt.HAS_ARG, "-s,--max-seconds"/"," }), ({ "tests", Getopt.HAS_ARG, "-t,--tests"/"," }), })), array opt)
284c2a2002-12-06Martin Nilsson  switch(opt[0]) { case "help": write(help, sizeof(tests)); return 0; case "maxrun": maximum_runs = (int)opt[1]; break; case "maxsec": seconds_per_test = (int)opt[1]; break;
2c52e42002-12-17Per Hedbor  case "tests":
4d8f242003-07-30Martin Stjernholm  test_globs = opt[1] / ",";
284c2a2002-12-06Martin Nilsson  }
a3b12a2003-01-19Martin Nilsson  int ecode; ecode += Tools.Shoot.ExecTest("Overhead",Tools.Shoot.Overhead())
284c2a2002-12-06Martin Nilsson  ->run(0,1,1); // fill caches write("test total user mem (runs)\n");
4d8f242003-07-30Martin Stjernholm  /* Run overhead check first by default. */ array(string) to_run = ({"Overhead"}) + (sort (indices (tests)) - ({"Overhead"})); array(string) to_run_names = rows (tests, to_run)->name; foreach (test_globs, string test_glob) foreach (to_run; int idx; string id) if (id && glob (test_glob, to_run_names[idx])) { ecode += Tools.Shoot.ExecTest(id,tests[id]) ->run(seconds_per_test,maximum_runs); // Don't run test more than once if it matches several globs. to_run[idx] = 0; }
a3b12a2003-01-19Martin Nilsson  return ecode;
284c2a2002-12-06Martin Nilsson }