Home
Search Perl pages
Subjects
By activity
Professions, Sciences, Humanities, Business, ...
User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...
Text Strings
Conversions, tests, processing, manipulation,...
Math
Integer, Floating point, Matrix, Statistics, Boolean, ...
Processing
Algorithms, Memory, Process control, Debugging, ...
Stored Data
Data storage, Integrity, Encryption, Compression, ...
Communications
Networks, protocols, Interprocess, Remote, Client Server, ...
Hard World Timing, Calendar and Clock, Audio, Video, Printer, Controls...
File System
Management, Filtering, File & Directory access, Viewers, ...
|
|
|
In general, you may not be able to. The Time::HiRes module (available from
CPAN) provides this functionality for some systems.
In general, you may not be able to. But if you system supports both the
syscall() function in Perl as well as a system call like
gettimeofday(2), then you may be able to do something like
this:
require 'sys/syscall.ph';
$TIMEVAL_T = "LL";
$done = $start = pack($TIMEVAL_T, ());
syscall( &SYS_gettimeofday, $start, 0)) != -1
or die "gettimeofday: $!";
##########################
# DO YOUR OPERATION HERE #
##########################
syscall( &SYS_gettimeofday, $done, 0) != -1
or die "gettimeofday: $!";
@start = unpack($TIMEVAL_T, $start);
@done = unpack($TIMEVAL_T, $done);
# fix microseconds
for ($done[1], $start[1]) { $_ /= 1_000_000 }
$delta_time = sprintf "%.4f", ($done[0] + $done[1] )
-
($start[0] + $start[1] );
Source: Perl FAQ: System Interaction Copyright: Copyright (c) 1997 Tom Christiansen and Nathan Torkington. |
Next: How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Previous: How can I sleep() or alarm() for under a second?
(Corrections, notes, and links courtesy of RocketAware.com)
Up to: Real-Time related
Rapid-Links:
Search | About | Comments | Submit Path: RocketAware > Perl >
perlfaq8/How_can_I_measure_time_under_a_s.htm
RocketAware.com is a service of Mib Software Copyright 2000, Forrest J. Cavalier III. All Rights Reserved. We welcome submissions and comments
|