Re: the time a program runs



Octavian Rasnita wrote:
Hi,

I have tried to find out the time a perl program runs, and I have used:

#at the start of the program:
my $begin = (times)[0];
my $begin_t = time();

... The program follows

# at the end of the program:
my $end = (times)[0] - $begin;
my $end_t = time() - $begin_t;
print "end: $end\nEnd_t: $end_t\n";

After running the program, it prints:

end: 4.953
End_t: 19

Why does this difference appear?


The program is a very short one, for testing the speed of Storable module.


Try this:

The global var $^T stores the time of execution start.
So at the end you want:

print (time() - $^T) , " seconds to complete\n";

However, if you want more accuracy then you might consider Time::HiRes or better yet Benchmark. Benchmark is a very useful tool.
.




Relevant Pages

  • Re: Alternative COBOL "telco" source program
    ... FYI, I have never written a line of COBOL in my life although I admit that, ... time between these two points in the program's execution. ... program that implements this benchmark and run it several times the elapsed ... calculation versus the time for i/o only. ...
    (comp.lang.cobol)
  • Re: measuring clock cycles per second
    ... executes the algorithm and writes a report on the various timings ... cycle execution of the algorithm (to report the number lock cycles to ... compare that to the same benchmark on your hardware. ... clock cycles to complete. ...
    (comp.os.linux.development.apps)
  • Re: JVM vs. EXE comaprison
    ... >> Startup time is added to the benchmark, and as such isnt measuring Java ... > The benchmark clearly is measuring Java execution performance. ...
    (comp.lang.java.programmer)
  • Re: Benchmarking MySQL on Solaris 10
    ... doing some tests and benchmark on MySQL performances. ... Doing OLTP test. ... OLTP test statistics: ... total time taken by event execution: ...
    (comp.unix.solaris)
  • Re: Advice to adult victims of cyberbullying
    ... It's much more fun to be way off topic and way out of ... Your posted benchmark results suggest a the C# solution executes ... I am not sure that comparative performance matters, ... comparing execution performance, C won. ...
    (comp.programming)