Skip to content

Commit

Permalink
Add support for timeDelta.totalMicroseconds and totalMilliseconds (#2…
Browse files Browse the repository at this point in the history
…6798)

[reviewed by @DanilaFe and @bradcray]

Resolves #26658 

Note that the implementation for totalMicroseconds is strongly based on
the suggestion from ajpotts, so credit to it should go to her and the
Arkouda team.

Updated some tests and a module that were converting the result of
totalSeconds to microseconds so that they use the new method instead.

Added a test of the new methods.

Passed a standard paratest with futures and a performance run of
`test/studies/ssca2` looked to be at the same granularity for the units
printed out.
  • Loading branch information
lydia-duncan authored Mar 4, 2025
2 parents 6b0074d + bfa6384 commit f2e0ad8
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules/packages/NPBRandom.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
*/
proc oddTimeSeed(): int(64) {
use Time;
const seed = (timeSinceEpoch().totalSeconds()*1_000_000): int;
const seed = timeSinceEpoch().totalMicroseconds();
const oddseed = if seed % 2 == 0 then seed + 1 else seed;
return oddseed;
}
Expand Down
11 changes: 11 additions & 0 deletions modules/standard/Time.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,17 @@ module Time {
return days*(24*60*60) + seconds + microseconds / 1000000.0;
}

/* Return the total number of milliseconds represented by this object */
@unstable("'timeDelta.totalMilliseconds()' is unstable because it is new")
proc timeDelta.totalMilliseconds(): real {
return (days*(24*60*60) + seconds)*1000 + microseconds / 1000.0;
}

/* Return the total number of microseconds represented by this object */
@unstable("'timeDelta.totalMicroseconds()' is unstable because it is new")
proc timeDelta.totalMicroseconds(): int {
return (days*(24*60*60) + seconds)*1_000_000 + microseconds;
}

/* Operators on timeDelta values */

Expand Down
7 changes: 7 additions & 0 deletions test/library/standard/Time/dateTime/checkTotalMicro.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use Time;

var a = new timeDelta(microseconds=10);
writeln(a.totalMicroseconds());

var b = new timeDelta(minutes=2, seconds=3);
writeln(b.totalMicroseconds());
2 changes: 2 additions & 0 deletions test/library/standard/Time/dateTime/checkTotalMicro.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
10
123000000
7 changes: 7 additions & 0 deletions test/library/standard/Time/dateTime/checkTotalMilli.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use Time;

var a = new timeDelta(milliseconds=10);
writeln(isClose(a.totalMilliseconds(), 10.0));

var b = new timeDelta(minutes=2, seconds=3);
writeln(isClose(b.totalMilliseconds(), 123000.0));
2 changes: 2 additions & 0 deletions test/library/standard/Time/dateTime/checkTotalMilli.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
true
true
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ proc Gen_RMAT_graph ( a : real,

var rndPos = 1;
const seed = if REPRODUCIBLE_PROBLEMS then 0556707007
else (timeSinceEpoch().totalSeconds()*1_000_000+1):int;
else timeSinceEpoch().totalMicroseconds()+1;

const delta = n_raw_edges + 1; // 1 corresponds to 'skip' in "old" code
rndPos += 1; // start with a skip
Expand Down
4 changes: 2 additions & 2 deletions test/users/franzf/v0/chpl/main.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ proc main() {
}

// benchmark computation
startTime = timeSinceEpoch().totalSeconds() * 1_000_000;
startTime = timeSinceEpoch().totalMicroseconds();
for i in 1..NUMRUNS {
fft(N, Y, X);
}
execTime = (timeSinceEpoch().totalSeconds()*1_000_000 - startTime)/NUMRUNS;
execTime = (timeSinceEpoch().totalMicroseconds() - startTime)/NUMRUNS;
if (printTimings) then
writeln("fft_", N, ": ", execTime, "us = ", ops / execTime, " Mflop/s");
else
Expand Down
4 changes: 2 additions & 2 deletions test/users/franzf/v1/chpl/main.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ proc main() {
}

// benchmark computation
startTime = timeSinceEpoch().totalSeconds()*1_000_000;
startTime = timeSinceEpoch().totalMicroseconds();
for i in 1..NUMRUNS {
fft(N, Y, X);
}
execTime = (timeSinceEpoch().totalSeconds()*1_000_000 - startTime)/NUMRUNS;
execTime = (timeSinceEpoch().totalMicroseconds() - startTime)/NUMRUNS;
if (printTimings) then
writeln("fft_", N, ": ", execTime, "us = ", ops / execTime, " Mflop/s");
else
Expand Down
4 changes: 2 additions & 2 deletions test/users/franzf/v2/chpl/main.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ proc main() {
}

// benchmark computation
startTime = timeSinceEpoch().totalSeconds()*1_000_000;
startTime = timeSinceEpoch().totalMicroseconds();
for i in 1..NUMRUNS {
fft(N, Y, X);
}
execTime = (timeSinceEpoch().totalSeconds()*1_000_000 - startTime)/NUMRUNS;
execTime = (timeSinceEpoch().totalMicroseconds() - startTime)/NUMRUNS;
if (printTimings) then
writeln("fft_", N, ": ", execTime, "us = ", ops / execTime, " Mflop/s");
else
Expand Down

0 comments on commit f2e0ad8

Please sign in to comment.