{
    "mode": "perldoc",
    "parameter": "Time::HiRes",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Time%3A%3AHiRes/json",
    "generated": "2026-06-11T00:22:59Z",
    "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 timers\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\", \"nanosleep\", \"ualarm\",\n\"gettimeofday\", and \"setitimer\"/\"getitimer\" system calls, in other words, high resolution time\nand timers. See the \"EXAMPLES\" section below and the test scripts for usage; see your system\ndocumentation for the description of the underlying \"nanosleep\" or \"usleep\", \"ualarm\",\n\"gettimeofday\", and \"setitimer\"/\"getitimer\" calls.\n\nIf your system lacks \"gettimeofday()\" or an emulation of it you don't get \"gettimeofday()\" or\nthe one-argument form of \"tvinterval()\". If your system lacks all of \"nanosleep()\", \"usleep()\",\n\"select()\", and \"poll\", you don't get \"Time::HiRes::usleep()\", \"Time::HiRes::nanosleep()\", or\n\"Time::HiRes::sleep()\". If your system lacks 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 will fail at compile\ntime.\n\nIf your subsecond sleeping is implemented with \"nanosleep()\" instead of \"usleep()\", you can mix\nsubsecond sleeping with signals since \"nanosleep()\" does not use signals. This, however, is not\nportable, and you should first check for the truth value of &Time::HiRes::dnanosleep to see\nwhether you have nanosleep, and then carefully read your \"nanosleep()\" C API documentation for\nany peculiarities.\n\nIf you are using \"nanosleep\" for something else than mixing sleeping with signals, give some\nthought to whether Perl is the tool you should be using for work requiring nanosecond\naccuracies.\n\nRemember that unless you are working on a *hard realtime* system, any clocks and timers will be\nimprecise, especially so if you are working in a pre-emptive multiuser system. Understand the\ndifference between *wallclock time* and process time (in UNIX-like systems the sum of *user* and\n*system* times). Any attempt to sleep for X seconds will most probably end up sleeping more than\nthat, but don't be surprised if you end up sleeping slightly less.\n\nThe following functions can be imported from this module. No functions are exported by default.\n\ngettimeofday ()\nIn array context returns a two-element array with the seconds and microseconds since the\nepoch. In scalar context returns floating seconds like \"Time::HiRes::time()\" (see below).\n\nusleep ( $useconds )\nSleeps for the number of microseconds (millionths of a second) specified. Returns the number\nof microseconds actually slept. Can sleep for more than one second, unlike the \"usleep\"\nsystem call. Can also sleep for zero seconds, which often works like a *thread yield*. See\nalso \"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. Returns the number of\nnanoseconds actually slept (accurate only to microseconds, the nearest thousand of them).\nCan sleep for more than one second. Can also sleep for zero seconds, which often works like\na *thread yield*. See also \"Time::HiRes::sleep()\", \"Time::HiRes::usleep()\", and\n\"clocknanosleep()\".\n\nDo not expect nanosleep() to be exact down to one nanosecond. Getting even accuracy of one\nthousand nanoseconds is good.\n\nualarm ( $useconds [, $intervaluseconds ] )\nIssues a \"ualarm\" call; the $intervaluseconds is optional and will be zero if unspecified,\nresulting in \"alarm\"-like behaviour.\n\nReturns the remaining time in the alarm in microseconds, or \"undef\" if 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 have been returned by\n\"gettimeofday()\". If the second argument is omitted, then the current time is used.\n\ntime ()\nReturns a floating seconds since the epoch. This function can be imported, resulting in a\nnice drop-in replacement for the \"time\" provided with core Perl; see the \"EXAMPLES\" below.\n\nNOTE 1: This higher resolution timer can return values either less or more than the core\n\"time()\", depending on whether your platform rounds the higher resolution timer values up,\ndown, or to the nearest second to get the core \"time()\", but naturally the difference should\nbe never more than half a second. See also \"clockgetres\", if available in your system.\n\nNOTE 2: Since Sunday, September 9th, 2001 at 01:46:40 AM GMT, when the \"time()\" seconds\nsince epoch rolled over to 1000000000, the default floating point format of Perl and the\nseconds since epoch have 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 six as promised\n(microseconds). Not to worry, the microseconds are there (assuming your platform supports\nsuch granularity in the first place). What is going on is that the default floating point\nformat of Perl only outputs 15 digits. In this case that means ten digits before the decimal\nseparator and five after. To see the microseconds you can use either \"printf\"/\"sprintf\" with\n\"%.6f\", or the \"gettimeofday()\" function in list context, which will give you the seconds\nand microseconds as two separate values.\n\nsleep ( $floatingseconds )\nSleeps for the specified amount of seconds. Returns the number of seconds actually slept (a\nfloating point value). This function can be imported, resulting in a nice drop-in\nreplacement for the \"sleep\" provided 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. Implemented using\n\"setitimer()\" if available, \"ualarm()\" if not. The $intervalfloatingseconds argument is\noptional and will be zero if unspecified, resulting in \"alarm()\"-like behaviour. This\nfunction can be imported, resulting in a nice drop-in replacement for the \"alarm\" provided\nwith perl, see the \"EXAMPLES\" below.\n\nReturns the remaining time in the alarm in seconds, or \"undef\" if an error occurred.\n\nNOTE 1: With some combinations of operating systems and Perl releases \"SIGALRM\" restarts\n\"select()\", instead of interrupting it. This means that an \"alarm()\" followed by a\n\"select()\" may together take 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) arrives, and more\nsignals may keep arriving at certain intervals. To disable an \"itimer\", use\n$floatingseconds of zero. If the $intervalfloatingseconds is set to zero (or\nunspecified), the timer is disabled after the next delivered signal.\n\nUse of interval timers may interfere with \"alarm()\", \"sleep()\", and \"usleep()\". In\nstandard-speak the \"interaction is unspecified\", which means that *anything* may happen: it\nmay 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 returned.\n\nThere are usually three or four interval timers (signals) available: the $which can be\n\"ITIMERREAL\", \"ITIMERVIRTUAL\", \"ITIMERPROF\", or \"ITIMERREALPROF\". Note that which ones\nare available depends: true UNIX platforms usually have the first three, but only Solaris\nseems to have \"ITIMERREALPROF\" (which is used to profile multithreaded programs). Win32\nunfortunately does not have interval timers.\n\n\"ITIMERREAL\" results in \"alarm()\"-like behaviour. Time is counted in *real time*; that is,\nwallclock time. \"SIGALRM\" is delivered when the timer expires.\n\n\"ITIMERVIRTUAL\" counts time in (process) *virtual time*; that is, only when the process is\nrunning. In multiprocessor/user/CPU systems this may be more or less than real or wallclock\ntime. (This time is also known as the *user time*.) \"SIGVTALRM\" is delivered when the timer\nexpires.\n\n\"ITIMERPROF\" counts time when either the process virtual time or when the operating system\nis running on behalf of the process (such as I/O). (This time is also known as the *system\ntime*.) (The sum of user time and system time is known as the *CPU time*.) \"SIGPROF\" is\ndelivered when the timer expires. \"SIGPROF\" can interrupt system calls.\n\nThe semantics of interval timers for multithreaded programs are system-specific, and some\nsystems may support additional interval timers. For example, it is unspecified which thread\ngets the signals. 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 returned. The interval is\nalways what you put in using \"setitimer()\".\n\nclockgettime ( $which )\nReturn as seconds the current value of the POSIX high resolution timer specified by $which.\nAll implementations that support POSIX high resolution timers are supposed to support at\nleast the $which value of \"CLOCKREALTIME\", which is supposed to return results close to the\nresults of \"gettimeofday\", or the number of seconds since 00:00:00:00 January 1, 1970\nGreenwich Mean Time (GMT). Do not assume that CLOCKREALTIME is zero, it might be one, or\nsomething else. Another potentially useful (but not available everywhere) value is\n\"CLOCKMONOTONIC\", which guarantees a monotonically increasing time value (unlike time() or\ngettimeofday(), which can be adjusted). See your system documentation for other possibly\nsupported values.\n\nclockgetres ( $which )\nReturn as seconds the resolution of the POSIX high resolution timer specified by $which. All\nimplementations that support POSIX high resolution timers are supposed to support at least\nthe $which value of \"CLOCKREALTIME\", see \"clockgettime\".\n\nNOTE: the resolution returned may be highly optimistic. Even if the resolution is high (a\nsmall number), all it means is that you'll be able to specify the arguments to\nclockgettime() and clocknanosleep() with that resolution. The system might not actually be\nable to measure events at that resolution, and the various overheads and the overall system\nload are certain to affect any timings.\n\nclocknanosleep ( $which, $nanoseconds, $flags = 0)\nSleeps for the number of nanoseconds (1e9ths of a second) specified. Returns the number of\nnanoseconds actually slept. The $which is the \"clock id\", as with clockgettime() and\nclockgetres(). The flags default to zero but \"TIMERABSTIME\" can specified (must be\nexported explicitly) which means that $nanoseconds is not a time interval (as is the\ndefault) but instead an absolute time. Can sleep for more than one second. Can also sleep\nfor zero seconds, which often works like 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. Getting even accuracy of\none thousand nanoseconds is good.\n",
            "subsections": [
                {
                    "name": "clock",
                    "content": "Return as seconds the *process time* (user + system time) spent by the process since the\nfirst call to clock() (the definition is not \"since the start of the process\", though if you\nare lucky these times may be quite close to each other, depending on the system). What this\nmeans is that you probably need to store the result of your first call to clock(), and\nsubtract that value from the following results of clock().\n\nThe time returned also includes the process times of the terminated child processes for\nwhich wait() has been executed. This value is somewhat like the second value returned by the\ntimes() of core Perl, but not necessarily identical. Note that due to backward compatibility\nlimitations the returned value may wrap around at about 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 access/modify/change file\ntimestamps in subsecond resolution, if the operating system and the filesystem both support\nsuch timestamps. To override the standard stat():\n\nuse Time::HiRes qw(stat);\n\nTest for the value of &Time::HiRes::dhiresstat to find out whether the operating system\nsupports subsecond file timestamps: a value larger than zero means yes. There are\nunfortunately no easy ways to find out whether the filesystem supports such timestamps. UNIX\nfilesystems often do; NTFS does; FAT doesn't (FAT timestamp granularity is two seconds).\n\nA zero return value of &Time::HiRes::dhiresstat means that Time::HiRes::stat is a no-op\npassthrough for CORE::stat() (and likewise for lstat), and therefore the timestamps will\nstay integers. The same thing will happen if the filesystem does not do subsecond\ntimestamps, even if the &Time::HiRes::dhiresstat is non-zero.\n\nIn any case do not expect nanosecond resolution, or even a microsecond resolution. Also note\nthat the modify/access timestamps might have different resolutions, and that they need not\nbe synchronized, 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 time stamp from t1: it may\nbe equal or *less*.\n\nutime LIST\nAs \"utime\" in perlfunc but with the ability to set the access/modify file timestamps in\nsubsecond resolution, if the operating system and the filesystem, and the mount options of\nthe filesystem, all support such 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 whether the operating system\nsupports setting subsecond file timestamps.\n\nAs with CORE::utime(), passing undef as both the atime and mtime will call the syscall with\na NULL argument.\n\nThe actual achievable subsecond resolution depends on the combination of the operating\nsystem and the filesystem.\n\nModifying the timestamps may not be possible at all: for example, the \"noatime\" filesystem\nmount option may prohibit you from changing the access time timestamp.\n\nReturns the number of files successfully changed.\n"
                }
            ]
        },
        "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 extension writers. The\nfollowing C functions are available in the modglobal 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 with different\nrepresentations. The names \"NVtime\" and \"U2time\" were selected mainly because they are operating\nsystem independent. (\"gettimeofday\" is Unix-centric, though some platforms like Win32 and VMS\nhave 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 microseconds) more than\n1000000 and setitimer() is not available in your 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 become negative just\nbecame 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 resolution and later than\none 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. What this means is that the\ncore \"time()\" may be reporting the time as one second later than \"gettimeofday()\" and\n\"Time::HiRes::time()\".\n\nAdjusting the system clock (either manually or by services like ntp) may cause problems,\nespecially for long running programs that assume a monotonously increasing time (note that all\nplatforms do not adjust time as gracefully as UNIX ntp does). For example in Win32 (and derived\nplatforms like Cygwin and MinGW) the Time::HiRes::time() may temporarily drift off from the\nsystem clock (and the original time()) by up to 0.5 seconds. Time::HiRes will notice this\neventually and recalibrate. Note that since Time::HiRes 1.77 the clockgettime(CLOCKMONOTONIC)\nmight help in this (in case your system supports CLOCKMONOTONIC).\n\nSome systems have APIs but not implementations: for example QNX and Haiku have the interval\ntimer APIs but not the functionality.\n\nIn pre-Sierra macOS (pre-10.12, OS X) clockgetres(), clockgettime() and clocknanosleep() are\nemulated using the Mach timers; as a side effect of being emulated the CLOCKREALTIME and\nCLOCKMONOTONIC are the same timer.\n\ngnukfreebsd seems to have non-functional futimens() and utimensat() (at least as of 10.1):\ntherefore 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), clockgetres(3), clocknanosleep(3),",
            "subsections": [
                {
                    "name": "clock_settime",
                    "content": ""
                }
            ]
        },
        "AUTHORS": {
            "content": "D. Wegscheid <wegscd@whirlpool.com> R. Schertler <roderick@argon.org> J. Hietaniemi <jhi@iki.fi>\nG. 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 Hietaniemi. 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 under the same terms as\nPerl 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"
        }
    ]
}