| 1 | package Time::Nanos; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use autouse 'Carp' => qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | our $VERSION = 'v0.1.6'; | |||||||||||||||||||
| 10 | 1 | our @EXPORT = qw(nanos micros millis); | |||||||||||||||||||
| 11 | 1 | our $CLOCK = 0; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | require XSLoader; | |||||||||||||||||||
| 14 | 1 | XSLoader::load('Time::Nanos', $VERSION); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 8 | ▶ | sub nanos { | ||||||||||||||||||
|
Subroutine
nanos: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 17 | 8 | my $as_array = shift(); | |||||||||||||||||||
| 18 | 8 | my $ns = hrtime($Time::Nanos::CLOCK); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 8 | ▶ | if ($as_array) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 3 | my $sec = int($ns / 1_000_000_000); | |||||||||||||||||||
| 22 | 3 | my $nsec = $ns % 1_000_000_000; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 3 | return ($sec, $nsec); | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 5 | return $ns; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 5 | ▶ | sub micros { | ||||||||||||||||||
|
Subroutine
micros: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 31 | 5 | my $as_array = shift(); | |||||||||||||||||||
| 32 | 5 | my $ns = hrtime($Time::Nanos::CLOCK); | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 5 | ▶ | if ($as_array) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 2 | my $sec = int($ns / 1_000_000_000); | |||||||||||||||||||
| 36 | 2 | my $usec = int(($ns % 1_000_000_000) / 1000); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2 | return ($sec, $usec); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 3 | my $us = int($ns / 1000); | |||||||||||||||||||
| 42 | 3 | return $us; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 5 | ▶ | sub millis { | ||||||||||||||||||
|
Subroutine
millis: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 46 | 5 | my $as_array = shift(); | |||||||||||||||||||
| 47 | 5 | my $ns = hrtime($Time::Nanos::CLOCK); | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 5 | ▶ | if ($as_array) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 2 | my $sec = int($ns / 1_000_000_000); | |||||||||||||||||||
| 51 | 2 | my $msec = int(($ns % 1_000_000_000) / 1_000_000); | |||||||||||||||||||
| 52 | 2 | return ($sec, $msec); | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 3 | my $ms = int($ns / 1_000_000); | |||||||||||||||||||
| 56 | 3 | return $ms; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 5 | ▶ | sub clock_source { | ||||||||||||||||||
|
Subroutine
clock_source: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||
| 60 | 5 | my $input = shift(); | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 5 | ▶ | if (!defined $input) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 63 | 0 | croak("clock_source() requires an argument"); | |||||||||||||||||||
| 64 | ▶ | } elsif ($input eq "realtime" || $input eq "0") { | |||||||||||||||||||
|
Condition100%3/3
$input eq "realtime" or $input eq 0
MC/DC100%2/2
$input eq "realtime" or $input eq 0
$input eq "realtime"
$input eq 0
Truth table100%3/3
A or B
A= $input eq "realtime"B= $input eq 0
| |||||||||||||||||||||
| 65 | 2 | $CLOCK = 0; | |||||||||||||||||||
| 66 | ▶ | } elsif ($input eq "monotonic" || $input eq "1") { | |||||||||||||||||||
|
Condition100%3/3
$input eq "monotonic" or $input eq 1
MC/DC100%2/2
$input eq "monotonic" or $input eq 1
$input eq "monotonic"
$input eq 1
Truth table100%3/3
A or B
A= $input eq "monotonic"B= $input eq 1
| |||||||||||||||||||||
| 67 | 2 | $CLOCK = 1; | |||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||
| 69 | 1 | croak("Unknown source '$input'"); | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | 1; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||