-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
common-dylan/timers.dylan: new function microsecond-counter
I needed some kind of low-level system counter to implement a clock() built-in while writing the interpreter in Crafting Interpreters and common-dylan:timers has almost the right thing and seems a natural place to add one.
- Loading branch information
Showing
5 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Module: common-dylan-test-suite | ||
|
||
|
||
define test test-microsecond-counter () | ||
let t1 = microsecond-counter(); | ||
sleep(0.1); | ||
let t2 = microsecond-counter(); | ||
let diff = t2 - t1; | ||
// I need slop to be at least 5200 on my macOS M3 Pro. Be more generous than | ||
// that since the main point is simply to exercise the function at all. --cgay | ||
let slop = 50_000; | ||
assert-true(diff >= (100_000 - slop) & diff < (100_000 + slop), | ||
diff); | ||
end test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters