Bug 458256. Use LoadLibraryW instead of LoadLibrary (patch by DougT). r+sr=vlad
[wine-gecko.git] / tools / performance / startup / gettime.pl
blob46697782e16bac7bde5619097ed429c0a0591f6d
1 #!/usr/bin/perl
3 # Use high resolution routines if installed (on win32 or linux), using
4 # eval as try/catch block around import of modules. Otherwise, just use 'time()'.
6 # 'Win32::API' <http://www.activestate.com/PPMPackages/zips/5xx-builds-only/Win32-API.zip>
7 # 'Time::HiRes' <http://search.cpan.org/search?dist=Time-HiRes>
8 # (also: http://rpmfind.net/linux/rpm2html/search.php?query=perl-Time-HiRes)
10 package Time::PossiblyHiRes;
12 use strict;
14 #use Time::HiRes qw(gettimeofday);
16 my $getLocalTime; # for win32
17 my $lpSystemTime = pack("SSSSSSSS"); # for win32
18 my $timesub; # code ref
20 # returns 12 char string "'s'x9.'m'x3" which is milliseconds since epoch,
21 # although resolution may vary depending on OS and installed packages
23 sub getTime () {
25 return &$timesub
26 if $timesub;
28 $timesub = sub { time() . "000"; }; # default
30 return &$timesub
31 if $^O eq "MacOS"; # don't know a better way on Mac
33 if ($^O eq "MSWin32") {
34 eval "use Win32::API;";
35 $timesub = sub {
36 # pass pointer to struct, void return
37 $getLocalTime =
38 eval "new Win32::API('kernel32', 'GetLocalTime', [qw{P}], qw{V});"
39 unless $getLocalTime;
40 $getLocalTime->Call($lpSystemTime);
41 my @t = unpack("SSSSSSSS", $lpSystemTime);
42 sprintf("%9s%03s", time(), pop @t);
43 } if !$@;
46 # ass-u-me if not mac/win32, then we're on a unix flavour
47 else {
48 eval "use Time::HiRes qw(gettimeofday);";
49 $timesub = sub {
50 my @t = gettimeofday();
51 $t[0]*1000 + int($t[1]/1000);
52 } if !$@;
55 return &$timesub;
61 # Test script to compare with low-res time:
63 # require "gettime.pl";
65 # use POSIX qw(strftime);
67 # print "hires time = " . Time::PossiblyHiRes::getTime() . "\n";
68 # print "lowres time = " . time() . "\n";
72 # end package