{
    "mode": "perldoc",
    "parameter": "Time::HiRes",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Time%3A%3AHiRes/json",
    "generated": "2026-05-30T06:08:12Z",
    "synopsis": "use Time::HiRes qw( usleep ualarm gettimeofday tvinterval nanosleep\nclockgettime clockgetres clocknanosleep clock\nstat lstat utime);\nusleep ($microseconds);\nnanosleep ($nanoseconds);\nualarm ($microseconds);\nualarm ($microseconds, $intervalmicroseconds);\n$t0 = [gettimeofday];\n($seconds, $microseconds) = gettimeofday;\n$elapsed = tvinterval ( $t0, [$seconds, $microseconds]);\n$elapsed = tvinterval ( $t0, [gettimeofday]);\n$elapsed = tvinterval ( $t0 );\nuse Time::HiRes qw ( time alarm sleep );\n$nowfractions = time;\nsleep ($floatingseconds);\nalarm ($floatingseconds);\nalarm ($floatingseconds, $floatinginterval);\nuse Time::HiRes qw( setitimer getitimer );\nsetitimer ($which, $floatingseconds, $floatinginterval );\ngetitimer ($which);\nuse Time::HiRes qw( clockgettime clockgetres clocknanosleep\nITIMERREAL ITIMERVIRTUAL ITIMERPROF\nITIMERREALPROF );\n$realtime   = clockgettime(CLOCKREALTIME);\n$resolution = clockgetres(CLOCKREALTIME);\nclocknanosleep(CLOCKREALTIME, 1.5e9);\nclocknanosleep(CLOCKREALTIME, time()*1e9 + 10e9, TIMERABSTIME);\nmy $ticktock = clock();\nuse Time::HiRes qw( stat lstat );\nmy @stat = stat(\"file\");\nmy @stat = stat(FH);\nmy @stat = lstat(\"file\");\nuse Time::HiRes qw( utime );\nutime $floatingseconds, $floatingseconds, file...;",
    "sections": {
        "NAME": {
            "content": "Time::HiRes - High resolution alarm, sleep, gettimeofday, interval\ntimers\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Time::HiRes qw( usleep ualarm gettimeofday tvinterval nanosleep\nclockgettime clockgetres clocknanosleep clock\nstat lstat utime);\n\nusleep ($microseconds);\nnanosleep ($nanoseconds);\n\nualarm ($microseconds);\nualarm ($microseconds, $intervalmicroseconds);\n\n$t0 = [gettimeofday];\n($seconds, $microseconds) = gettimeofday;\n\n$elapsed = tvinterval ( $t0, [$seconds, $microseconds]);\n$elapsed = tvinterval ( $t0, [gettimeofday]);\n$elapsed = tvinterval ( $t0 );\n\nuse Time::HiRes qw ( time alarm sleep );\n\n$nowfractions = time;\nsleep ($floatingseconds);\nalarm ($floatingseconds);\nalarm ($floatingseconds, $floatinginterval);\n\nuse Time::HiRes qw( setitimer getitimer );\n\nsetitimer ($which, $floatingseconds, $floatinginterval );\ngetitimer ($which);\n\nuse Time::HiRes qw( clockgettime clockgetres clocknanosleep\nITIMERREAL ITIMERVIRTUAL ITIMERPROF\nITIMERREALPROF );\n\n$realtime   = clockgettime(CLOCKREALTIME);\n$resolution = clockgetres(CLOCKREALTIME);\n\nclocknanosleep(CLOCKREALTIME, 1.5e9);\nclocknanosleep(CLOCKREALTIME, time()*1e9 + 10e9, TIMERABSTIME);\n\nmy $ticktock = clock();\n\nuse Time::HiRes qw( stat lstat );\n\nmy @stat = stat(\"file\");\nmy @stat = stat(FH);\nmy @stat = lstat(\"file\");\n\nuse Time::HiRes qw( utime );\nutime $floatingseconds, $floatingseconds, file...;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The \"Time::HiRes\" module implements a Perl interface to the \"usleep\",\n\"nanosleep\", \"ualarm\", \"gettimeofday\", and \"setitimer\"/\"getitimer\"\nsystem calls, in other words, high resolution time and timers. See the\n\"EXAMPLES\" section below and the test scripts for usage; see your system\ndocumentation for the description of the underlying \"nanosleep\" or\n\"usleep\", \"ualarm\", \"gettimeofday\", and \"setitimer\"/\"getitimer\" calls.\n\nIf your system lacks \"gettimeofday()\" or an emulation of it you don't\nget \"gettimeofday()\" or the one-argument form of \"tvinterval()\". If\nyour system lacks all of \"nanosleep()\", \"usleep()\", \"select()\", and\n\"poll\", you don't get \"Time::HiRes::usleep()\",\n\"Time::HiRes::nanosleep()\", or \"Time::HiRes::sleep()\". If your system\nlacks both \"ualarm()\" and \"setitimer()\" you don't get\n\"Time::HiRes::ualarm()\" or \"Time::HiRes::alarm()\".\n\nIf you try to import an unimplemented function in the \"use\" statement it\nwill fail at compile time.\n\nIf your subsecond sleeping is implemented with \"nanosleep()\" instead of\n\"usleep()\", you can mix subsecond sleeping with signals since\n\"nanosleep()\" does not use signals. This, however, is not portable, and\nyou should first check for the truth value of &Time::HiRes::dnanosleep\nto see whether you have nanosleep, and then carefully read your\n\"nanosleep()\" C API documentation for any peculiarities.\n\nIf you are using \"nanosleep\" for something else than mixing sleeping\nwith signals, give some thought to whether Perl is the tool you should\nbe using for work requiring nanosecond accuracies.\n\nRemember that unless you are working on a *hard realtime* system, any\nclocks and timers will be imprecise, especially so if you are working in\na pre-emptive multiuser system. Understand the difference between\n*wallclock time* and process time (in UNIX-like systems the sum of\n*user* and *system* times). Any attempt to sleep for X seconds will most\nprobably end up sleeping more than that, but don't be surprised if you\nend up sleeping slightly less.\n\nThe following functions can be imported from this module. No functions\nare exported by default.\n\ngettimeofday ()\nIn array context returns a two-element array with the seconds and\nmicroseconds since the epoch. In scalar context returns floating\nseconds like \"Time::HiRes::time()\" (see below).\n\nusleep ( $useconds )\nSleeps for the number of microseconds (millionths of a second)\nspecified. Returns the number of microseconds actually slept. Can\nsleep for more than one second, unlike the \"usleep\" system call. Can\nalso sleep for zero seconds, which often works like a *thread\nyield*. See also \"Time::HiRes::sleep()\", and \"clocknanosleep()\".\n\nDo not expect usleep() to be exact down to one microsecond.\n\nnanosleep ( $nanoseconds )\nSleeps for the number of nanoseconds (1e9ths of a second) specified.\nReturns the number of nanoseconds actually slept (accurate only to\nmicroseconds, the nearest thousand of them). Can sleep for more than\none second. Can also sleep for zero seconds, which often works like\na *thread yield*. See also \"Time::HiRes::sleep()\",\n\"Time::HiRes::usleep()\", and \"clocknanosleep()\".\n\nDo not expect nanosleep() to be exact down to one nanosecond.\nGetting even accuracy of one thousand nanoseconds is good.\n\nualarm ( $useconds [, $intervaluseconds ] )\nIssues a \"ualarm\" call; the $intervaluseconds is optional and will\nbe zero if unspecified, resulting in \"alarm\"-like behaviour.\n\nReturns the remaining time in the alarm in microseconds, or \"undef\"\nif an error occurred.\n\nualarm(0) will cancel an outstanding ualarm().\n\nNote that the interaction between alarms and sleeps is unspecified.\n\ntvinterval\ntvinterval ( $reftogettimeofday [, $reftolatergettimeofday] )\n\nReturns the floating seconds between the two times, which should\nhave been returned by \"gettimeofday()\". If the second argument is\nomitted, then the current time is used.\n\ntime ()\nReturns a floating seconds since the epoch. This function can be\nimported, resulting in a nice drop-in replacement for the \"time\"\nprovided with core Perl; see the \"EXAMPLES\" below.\n\nNOTE 1: This higher resolution timer can return values either less\nor more than the core \"time()\", depending on whether your platform\nrounds the higher resolution timer values up, down, or to the\nnearest second to get the core \"time()\", but naturally the\ndifference should be never more than half a second. See also\n\"clockgetres\", if available in your system.\n\nNOTE 2: Since Sunday, September 9th, 2001 at 01:46:40 AM GMT, when\nthe \"time()\" seconds since epoch rolled over to 1000000000, the\ndefault floating point format of Perl and the seconds since epoch\nhave conspired to produce an apparent bug: if you print the value of\n\"Time::HiRes::time()\" you seem to be getting only five decimals, not\nsix as promised (microseconds). Not to worry, the microseconds are\nthere (assuming your platform supports such granularity in the first\nplace). What is going on is that the default floating point format\nof Perl only outputs 15 digits. In this case that means ten digits\nbefore the decimal separator and five after. To see the microseconds\nyou can use either \"printf\"/\"sprintf\" with \"%.6f\", or the\n\"gettimeofday()\" function in list context, which will give you the\nseconds and microseconds as two separate values.\n\nsleep ( $floatingseconds )\nSleeps for the specified amount of seconds. Returns the number of\nseconds actually slept (a floating point value). This function can\nbe imported, resulting in a nice drop-in replacement for the \"sleep\"\nprovided with perl, see the \"EXAMPLES\" below.\n\nNote that the interaction between alarms and sleeps is unspecified.\n\nalarm ( $floatingseconds [, $intervalfloatingseconds ] )\nThe \"SIGALRM\" signal is sent after the specified number of seconds.\nImplemented using \"setitimer()\" if available, \"ualarm()\" if not. The\n$intervalfloatingseconds argument is optional and will be zero if\nunspecified, resulting in \"alarm()\"-like behaviour. This function\ncan be imported, resulting in a nice drop-in replacement for the\n\"alarm\" provided with perl, see the \"EXAMPLES\" below.\n\nReturns the remaining time in the alarm in seconds, or \"undef\" if an\nerror occurred.\n\nNOTE 1: With some combinations of operating systems and Perl\nreleases \"SIGALRM\" restarts \"select()\", instead of interrupting it.\nThis means that an \"alarm()\" followed by a \"select()\" may together\ntake the sum of the times specified for the \"alarm()\" and the\n\"select()\", not just the time of the \"alarm()\".\n\nNote that the interaction between alarms and sleeps is unspecified.\n\nsetitimer ( $which, $floatingseconds [, $intervalfloatingseconds ] )\nStart up an interval timer: after a certain time, a signal ($which)\narrives, and more signals may keep arriving at certain intervals. To\ndisable an \"itimer\", use $floatingseconds of zero. If the\n$intervalfloatingseconds is set to zero (or unspecified), the\ntimer is disabled after the next delivered signal.\n\nUse of interval timers may interfere with \"alarm()\", \"sleep()\", and\n\"usleep()\". In standard-speak the \"interaction is unspecified\",\nwhich means that *anything* may happen: it may work, it may not.\n\nIn scalar context, the remaining time in the timer is returned.\n\nIn list context, both the remaining time and the interval are\nreturned.\n\nThere are usually three or four interval timers (signals) available:\nthe $which can be \"ITIMERREAL\", \"ITIMERVIRTUAL\", \"ITIMERPROF\", or\n\"ITIMERREALPROF\". Note that which ones are available depends: true\nUNIX platforms usually have the first three, but only Solaris seems\nto have \"ITIMERREALPROF\" (which is used to profile multithreaded\nprograms). Win32 unfortunately does not have interval timers.\n\n\"ITIMERREAL\" results in \"alarm()\"-like behaviour. Time is counted\nin *real time*; that is, wallclock time. \"SIGALRM\" is delivered when\nthe timer expires.\n\n\"ITIMERVIRTUAL\" counts time in (process) *virtual time*; that is,\nonly when the process is running. In multiprocessor/user/CPU systems\nthis may be more or less than real or wallclock time. (This time is\nalso known as the *user time*.) \"SIGVTALRM\" is delivered when the\ntimer expires.\n\n\"ITIMERPROF\" counts time when either the process virtual time or\nwhen the operating system is running on behalf of the process (such\nas I/O). (This time is also known as the *system time*.) (The sum of\nuser time and system time is known as the *CPU time*.) \"SIGPROF\" is\ndelivered when the timer expires. \"SIGPROF\" can interrupt system\ncalls.\n\nThe semantics of interval timers for multithreaded programs are\nsystem-specific, and some systems may support additional interval\ntimers. For example, it is unspecified which thread gets the\nsignals. See your setitimer(2) documentation.\n\ngetitimer ( $which )\nReturn the remaining time in the interval timer specified by $which.\n\nIn scalar context, the remaining time is returned.\n\nIn list context, both the remaining time and the interval are\nreturned. The interval is always what you put in using\n\"setitimer()\".\n\nclockgettime ( $which )\nReturn as seconds the current value of the POSIX high resolution\ntimer specified by $which. All implementations that support POSIX\nhigh resolution timers are supposed to support at least the $which\nvalue of \"CLOCKREALTIME\", which is supposed to return results close\nto the results of \"gettimeofday\", or the number of seconds since\n00:00:00:00 January 1, 1970 Greenwich Mean Time (GMT). Do not assume\nthat CLOCKREALTIME is zero, it might be one, or something else.\nAnother potentially useful (but not available everywhere) value is\n\"CLOCKMONOTONIC\", which guarantees a monotonically increasing time\nvalue (unlike time() or gettimeofday(), which can be adjusted). See\nyour system documentation for other possibly supported values.\n\nclockgetres ( $which )\nReturn as seconds the resolution of the POSIX high resolution timer\nspecified by $which. All implementations that support POSIX high\nresolution timers are supposed to support at least the $which value\nof \"CLOCKREALTIME\", see \"clockgettime\".\n\nNOTE: the resolution returned may be highly optimistic. Even if the\nresolution is high (a small number), all it means is that you'll be\nable to specify the arguments to clockgettime() and\nclocknanosleep() with that resolution. The system might not\nactually be able to measure events at that resolution, and the\nvarious overheads and the overall system load are certain to affect\nany timings.\n\nclocknanosleep ( $which, $nanoseconds, $flags = 0)\nSleeps for the number of nanoseconds (1e9ths of a second) specified.\nReturns the number of nanoseconds actually slept. The $which is the\n\"clock id\", as with clockgettime() and clockgetres(). The flags\ndefault to zero but \"TIMERABSTIME\" can specified (must be exported\nexplicitly) which means that $nanoseconds is not a time interval (as\nis the default) but instead an absolute time. Can sleep for more\nthan one second. Can also sleep for zero seconds, which often works\nlike a *thread yield*. See also \"Time::HiRes::sleep()\",\n\"Time::HiRes::usleep()\", and \"Time::HiRes::nanosleep()\".\n\nDo not expect clocknanosleep() to be exact down to one nanosecond.\nGetting even accuracy of one thousand nanoseconds is good.\n\nclock()\nReturn as seconds the *process time* (user + system time) spent by\nthe process since the first call to clock() (the definition is not\n\"since the start of the process\", though if you are lucky these\ntimes may be quite close to each other, depending on the system).\nWhat this means is that you probably need to store the result of\nyour first call to clock(), and subtract that value from the\nfollowing results of clock().\n\nThe time returned also includes the process times of the terminated\nchild processes for which wait() has been executed. This value is\nsomewhat like the second value returned by the times() of core Perl,\nbut not necessarily identical. Note that due to backward\ncompatibility limitations the returned value may wrap around at\nabout 2147 seconds or at about 36 minutes.\n\nstat\nstat FH\nstat EXPR\nlstat\nlstat FH\nlstat EXPR\nAs \"stat\" in perlfunc or \"lstat\" in perlfunc but with the\naccess/modify/change file timestamps in subsecond resolution, if the\noperating system and the filesystem both support such timestamps. To\noverride the standard stat():\n\nuse Time::HiRes qw(stat);\n\nTest for the value of &Time::HiRes::dhiresstat to find out whether\nthe operating system supports subsecond file timestamps: a value\nlarger than zero means yes. There are unfortunately no easy ways to\nfind out whether the filesystem supports such timestamps. UNIX\nfilesystems often do; NTFS does; FAT doesn't (FAT timestamp\ngranularity is two seconds).\n\nA zero return value of &Time::HiRes::dhiresstat means that\nTime::HiRes::stat is a no-op passthrough for CORE::stat() (and\nlikewise for lstat), and therefore the timestamps will stay\nintegers. The same thing will happen if the filesystem does not do\nsubsecond timestamps, even if the &Time::HiRes::dhiresstat is\nnon-zero.\n\nIn any case do not expect nanosecond resolution, or even a\nmicrosecond resolution. Also note that the modify/access timestamps\nmight have different resolutions, and that they need not be\nsynchronized, e.g. if the operations are\n\nwrite\nstat # t1\nread\nstat # t2\n\nthe access time stamp from t2 need not be greater-than the modify\ntime stamp from t1: it may be equal or *less*.\n\nutime LIST\nAs \"utime\" in perlfunc but with the ability to set the access/modify\nfile timestamps in subsecond resolution, if the operating system and\nthe filesystem, and the mount options of the filesystem, all support\nsuch timestamps.\n\nTo override the standard utime():\n\nuse Time::HiRes qw(utime);\n\nTest for the value of &Time::HiRes::dhiresutime to find out\nwhether the operating system supports setting subsecond file\ntimestamps.\n\nAs with CORE::utime(), passing undef as both the atime and mtime\nwill call the syscall with a NULL argument.\n\nThe actual achievable subsecond resolution depends on the\ncombination of the operating system and the filesystem.\n\nModifying the timestamps may not be possible at all: for example,\nthe \"noatime\" filesystem mount option may prohibit you from changing\nthe access time timestamp.\n\nReturns the number of files successfully changed.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "use Time::HiRes qw(usleep ualarm gettimeofday tvinterval);\n\n$microseconds = 750000;\nusleep($microseconds);\n\n# signal alarm in 2.5s & every .1s thereafter\nualarm(2500000, 100000);\n# cancel that ualarm\nualarm(0);\n\n# get seconds and microseconds since the epoch\n($s, $usec) = gettimeofday();\n\n# measure elapsed time\n# (could also do by subtracting 2 gettimeofday return values)\n$t0 = [gettimeofday];\n# do bunch of stuff here\n$t1 = [gettimeofday];\n# do more stuff here\n$t0t1 = tvinterval $t0, $t1;\n\n$elapsed = tvinterval ($t0, [gettimeofday]);\n$elapsed = tvinterval ($t0); # equivalent code\n\n#\n# replacements for time, alarm and sleep that know about\n# floating seconds\n#\nuse Time::HiRes;\n$nowfractions = Time::HiRes::time;\nTime::HiRes::sleep (2.5);\nTime::HiRes::alarm (10.6666666);\n\nuse Time::HiRes qw ( time alarm sleep );\n$nowfractions = time;\nsleep (2.5);\nalarm (10.6666666);\n\n# Arm an interval timer to go off first at 10 seconds and\n# after that every 2.5 seconds, in process virtual time\n\nuse Time::HiRes qw ( setitimer ITIMERVIRTUAL time );\n\n$SIG{VTALRM} = sub { print time, \"\\n\" };\nsetitimer(ITIMERVIRTUAL, 10, 2.5);\n\nuse Time::HiRes qw( clockgettime clockgetres CLOCKREALTIME );\n# Read the POSIX high resolution timer.\nmy $high = clockgettime(CLOCKREALTIME);\n# But how accurate we can be, really?\nmy $reso = clockgetres(CLOCKREALTIME);\n\nuse Time::HiRes qw( clocknanosleep TIMERABSTIME );\nclocknanosleep(CLOCKREALTIME, 1e6);\nclocknanosleep(CLOCKREALTIME, 2e9, TIMERABSTIME);\n\nuse Time::HiRes qw( clock );\nmy $clock0 = clock();\n... # Do something.\nmy $clock1 = clock();\nmy $clockd = $clock1 - $clock0;\n\nuse Time::HiRes qw( stat );\nmy ($atime, $mtime, $ctime) = (stat(\"istics\"))[8, 9, 10];\n",
            "subsections": []
        },
        "C API": {
            "content": "In addition to the perl API described above, a C API is available for\nextension writers. The following C functions are available in the\nmodglobal hash:\n\nname             C prototype\n---------------  ----------------------\nTime::NVtime     NV (*)()\nTime::U2time     void (*)(pTHX UV ret[2])\n\nBoth functions return equivalent information (like \"gettimeofday\") but\nwith different representations. The names \"NVtime\" and \"U2time\" were\nselected mainly because they are operating system independent.\n(\"gettimeofday\" is Unix-centric, though some platforms like Win32 and\nVMS have emulations for it.)\n\nHere is an example of using \"NVtime\" from C:\n\nNV (*myNVtime)(); /* Returns -1 on failure. */\nSV svp = hvfetchs(PLmodglobal, \"Time::NVtime\", 0);\nif (!svp)         croak(\"Time::HiRes is required\");\nif (!SvIOK(*svp)) croak(\"Time::NVtime isn't a function pointer\");\nmyNVtime = INT2PTR(NV(*)(), SvIV(*svp));\nprintf(\"The current time is: %\" NVff \"\\n\", (*myNVtime)());\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "useconds or interval more than ...\nIn ualarm() you tried to use number of microseconds or interval (also in\nmicroseconds) more than 1000000 and setitimer() is not available in\nyour system to emulate that case.\n\nnegative time not invented yet\nYou tried to use a negative time argument.\n\ninternal error: useconds < 0 (unsigned ... signed ...)\nSomething went horribly wrong-- the number of microseconds that cannot\nbecome negative just became negative. Maybe your compiler is broken?\n\nuseconds or uinterval equal to or more than 1000000\nIn some platforms it is not possible to get an alarm with subsecond\nresolution and later than one second.\n\nunimplemented in this platform\nSome calls simply aren't available, real or emulated, on every platform.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "Notice that the core \"time()\" maybe rounding rather than truncating.\nWhat this means is that the core \"time()\" may be reporting the time as\none second later than \"gettimeofday()\" and \"Time::HiRes::time()\".\n\nAdjusting the system clock (either manually or by services like ntp) may\ncause problems, especially for long running programs that assume a\nmonotonously increasing time (note that all platforms do not adjust time\nas gracefully as UNIX ntp does). For example in Win32 (and derived\nplatforms like Cygwin and MinGW) the Time::HiRes::time() may temporarily\ndrift off from the system clock (and the original time()) by up to 0.5\nseconds. Time::HiRes will notice this eventually and recalibrate. Note\nthat since Time::HiRes 1.77 the clockgettime(CLOCKMONOTONIC) might\nhelp in this (in case your system supports CLOCKMONOTONIC).\n\nSome systems have APIs but not implementations: for example QNX and\nHaiku have the interval timer APIs but not the functionality.\n\nIn pre-Sierra macOS (pre-10.12, OS X) clockgetres(), clockgettime()\nand clocknanosleep() are emulated using the Mach timers; as a side\neffect of being emulated the CLOCKREALTIME and CLOCKMONOTONIC are the\nsame timer.\n\ngnukfreebsd seems to have non-functional futimens() and utimensat() (at\nleast as of 10.1): therefore the hires utime() does not work.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Perl modules BSD::Resource, Time::TAI64.\n\nYour system documentation for clock(3), clockgettime(2),\nclockgetres(3), clocknanosleep(3), clocksettime(2), getitimer(2),\ngettimeofday(2), setitimer(2), sleep(3), stat(2), ualarm(3).\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "D. Wegscheid <wegscd@whirlpool.com> R. Schertler <roderick@argon.org> J.\nHietaniemi <jhi@iki.fi> G. Aas <gisle@aas.no>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "Copyright (c) 1996-2002 Douglas E. Wegscheid. All rights reserved.\n\nCopyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Jarkko\nHietaniemi. All rights reserved.\n\nCopyright (C) 2011, 2012, 2013 Andrew Main (Zefram) <zefram@fysh.org>\n\nThis program is free software; you can redistribute it and/or modify it\nunder the same terms as Perl itself.\n",
            "subsections": []
        }
    },
    "summary": "Time::HiRes - High resolution alarm, sleep, gettimeofday, interval timers",
    "flags": [],
    "examples": [
        "use Time::HiRes qw(usleep ualarm gettimeofday tvinterval);",
        "$microseconds = 750000;",
        "usleep($microseconds);",
        "# signal alarm in 2.5s & every .1s thereafter",
        "ualarm(2500000, 100000);",
        "# cancel that ualarm",
        "ualarm(0);",
        "# get seconds and microseconds since the epoch",
        "($s, $usec) = gettimeofday();",
        "# measure elapsed time",
        "# (could also do by subtracting 2 gettimeofday return values)",
        "$t0 = [gettimeofday];",
        "# do bunch of stuff here",
        "$t1 = [gettimeofday];",
        "# do more stuff here",
        "$t0t1 = tvinterval $t0, $t1;",
        "$elapsed = tvinterval ($t0, [gettimeofday]);",
        "$elapsed = tvinterval ($t0); # equivalent code",
        "# replacements for time, alarm and sleep that know about",
        "# floating seconds",
        "use Time::HiRes;",
        "$nowfractions = Time::HiRes::time;",
        "Time::HiRes::sleep (2.5);",
        "Time::HiRes::alarm (10.6666666);",
        "use Time::HiRes qw ( time alarm sleep );",
        "$nowfractions = time;",
        "sleep (2.5);",
        "alarm (10.6666666);",
        "# Arm an interval timer to go off first at 10 seconds and",
        "# after that every 2.5 seconds, in process virtual time",
        "use Time::HiRes qw ( setitimer ITIMERVIRTUAL time );",
        "$SIG{VTALRM} = sub { print time, \"\\n\" };",
        "setitimer(ITIMERVIRTUAL, 10, 2.5);",
        "use Time::HiRes qw( clockgettime clockgetres CLOCKREALTIME );",
        "# Read the POSIX high resolution timer.",
        "my $high = clockgettime(CLOCKREALTIME);",
        "# But how accurate we can be, really?",
        "my $reso = clockgetres(CLOCKREALTIME);",
        "use Time::HiRes qw( clocknanosleep TIMERABSTIME );",
        "clocknanosleep(CLOCKREALTIME, 1e6);",
        "clocknanosleep(CLOCKREALTIME, 2e9, TIMERABSTIME);",
        "use Time::HiRes qw( clock );",
        "my $clock0 = clock();",
        "... # Do something.",
        "my $clock1 = clock();",
        "my $clockd = $clock1 - $clock0;",
        "use Time::HiRes qw( stat );",
        "my ($atime, $mtime, $ctime) = (stat(\"istics\"))[8, 9, 10];"
    ],
    "see_also": [
        {
            "name": "clock",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/clock/3/json"
        },
        {
            "name": "clockgettime",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/clockgettime/2/json"
        },
        {
            "name": "clockgetres",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/clockgetres/3/json"
        },
        {
            "name": "clocknanosleep",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/clocknanosleep/3/json"
        },
        {
            "name": "clocksettime",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/clocksettime/2/json"
        },
        {
            "name": "getitimer",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/getitimer/2/json"
        },
        {
            "name": "gettimeofday",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/gettimeofday/2/json"
        },
        {
            "name": "setitimer",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/setitimer/2/json"
        },
        {
            "name": "sleep",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/sleep/3/json"
        },
        {
            "name": "stat",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/stat/2/json"
        },
        {
            "name": "ualarm",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/ualarm/3/json"
        }
    ]
}