The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

SPVM::Time::HiRes - High Resolution Time

Description

The Time::HiRes class in SPVM has methods to manipulate high resolution time.

Usage

  use Time::HiRes;
  use Sys::Time::Constant as TIME;
  use Sys::Time::Timeval;
  
  my $time = Time::HiRes->time;
  
  my $time = Time::HiRes->clock_gettime(TIME->CLOCK_MONOTONIC);
  
  Time::HiRes->sleep(3.5);
  
  Time::HiRes->usleep(3.5 * 1_000_000);
  
  my $time_tv = Time::HiRes->gettimeofday;
  
  {
    my $tv_a = Sys::Time::Timeval->new;
    $tv_a->set_tv_sec(1);
    $tv_a->set_tv_usec(900_000);
    
    my $tv_a = Sys::Time::Timeval->new;
    $tv_a->set_tv_sec(2);
    $tv_a->set_tv_usec(800_000);
    
    my $tv_interval = Time::HiRes->tv_interval($tv_a, $tv_b);
  }

Class Methods

gettimeofday

static method gettimeofday : Sys::Time::Timeval ();

Gets the time as a Sys::Time::Timeval object and returns it.

See the gettimeofday method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the gettimeofday method in the Sys::Time class could be thrown.

usleep

static method usleep : int ($usec : int);

Sleeps for microseconds $usec and returns remaining time.

See the usleep method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the usleep method in the Sys::Time class could be thrown.

nanosleep

static method nanosleep : long ($nanoseconds : long);

Sleeps for nanoseconds $nanoseconds and returns remaining time.

See the nanosleep method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the nanosleep method in the Sys::Time class could be thrown.

ualarm

  static method ualarm : int ($usecs : int, $interval : int = 0);

Alarm after microseconds $usecs with or without the microseconds interval $interval.

See the ualarm method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the ualarm method in the Sys::Signal class could be thrown.

tv_interval

static method tv_interval : double ($a : Sys::Time::Timeval, $b : Sys::Time::Timeval = undef);

Returns the floating seconds between the two times. If the second argument $b is omitted, then the current time is used.

time

static method time : double ();

Gets the time.

sleep

static method sleep : double ($float_seconds : double);

Sleeps for floating point seconds $float_seconds and retunrs remaining time.

Exceptions:

The exceptions thrown by the usleep method in the Sys::Time class could be thrown.

alarm

static method alarm : double ($float_seconds : double, $interval_float_seconds : double = 0);

Alarm after floating point seconds $float_seconds with or without the interval $interval_float_seconds.

Exceptions:

The exceptions thrown by the ualarm method in the Sys::Time class could be thrown.

setitimer

static method setitimer : Time::HiRes::ItimervalFloat ($which : int, $new_itimer_float : Time::HiRes::ItimervalFloat);

Start up an interval timer: after a certain time(and a interval) $new_itimer_float, a signal ($which) arrives.

See the setitimer method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the setitimer method in the Sys::Time class could be thrown.

getitimer

static method getitimer : Time::HiRes::ItimervalFloat ($which : int);

Return the remaining time in the interval timer specified by $which.

See the getitimer method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the getitimer method in the Sys::Time class could be thrown.

clock_gettime

static method clock_gettime : double ($clk_id : int)

Returns the time of the specified clock $clk_id.

See Sys::Time::Constant about constant values given to $clockid.

See the clock_gettime method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the clock_gettime method in the Sys::Time class could be thrown.

clock_gettime_timespec

static method clock_gettime_timespec : Sys::Time::Timespec ($clk_id : int);

Same as "clock_gettime", but returns a Sys::Time::Timespec object.

clock_getres

static method clock_getres : double ($clk_id : int)

Returns the resolution (precision) of the specified clock $clk_id.

See Sys::Time::Constant about constant values given to $clockid.

See the clock_getres method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the clock_getres method in the Sys::Time class could be thrown.

clock_getres_timespec

static method clock_getres_timespec : Sys::Time::Timespec ($clk_id : int);

Same as "clock_getres", but returns a Sys::Time::Timespec object.

clock_nanosleep

static method clock_nanosleep : long ($clockid : int, $nanoseconds : long, $flags : int = 0);

Sleeps for nanoseconds $nanoseconds and returns remaining time.

See Sys::Time::Constant about constant values given to $clockid and $flags.

See the clock_nanosleep method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the clock_nanosleep method in the Sys::Time class could be thrown.

clock

static method clock : long ();

Returns an approximation of processor time used by the program.

See the clock method in the Sys::Time class in detail.

Exceptions:

The exceptions thrown by the clock method in the Sys::Time class could be thrown.

Modules

See Also

Repository

SPVM::Time::HiRes - Github

Author

Yuki Kimoto kimoto.yuki@gmail.com

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License