Software developer at Arup, climber and open-source advocate from the Midlands UK.
dominicegginton / nanoseconds Goto Github PK
View Code? Open in Web Editor NEWSimple high-resolution timing for Swift
License: MIT License
Simple high-resolution timing for Swift
License: MIT License
Software developer at Arup, climber and open-source advocate from the Midlands UK.
Unless I'm reading the the code for this project wrong it suggests you have a fundamental misunderstanding of the TimeInterval
type in Swift.
TimeInterval
is measured in seconds. So if you wanted to initialise a TimeInterval
as a specific number of seconds you would initialise it directly, eg:
var seconds: TimeInterval = 10 // 10 seconds.
Your code instead has this:
public init (seconds: Double) { self = seconds * 1e+9 }
Which multiplies the stored TimeInterval
by 1_000_000_000. Making the value stored be some multiple of a billion seconds. If you then passed this value to any Swift API expecting a TimeInterval
you would be waiting a very long time.
I recommend you re-evaluate your assumptions here. Or better yet adopt the new iOS 16 Clock APIs.
If your intention was to create a Nanosecond
type this logic would make sense. But you shouldn't use a Double
(aka TimeInterval
) for that. Instead look at Int64
.
There don't seem to be unit tests that check that the subtraction values are reasonable. I had my own tests in my app, and sleeping for two seconds doesn't yield a difference greater than one second.
let before = Now()
sleep(2)
let after = Now()
XCTAssertGreaterThan((after - before).seconds, 1)
// XCTAssertGreaterThan failed: ("0.048024575") is not greater than ("1.0")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.