Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated "time" crate #40

Merged
merged 4 commits into from
Apr 11, 2019
Merged

Conversation

kolen
Copy link
Contributor

@kolen kolen commented Apr 9, 2019

Removed time crate, which is deprecated, replaced time::precise_time_ns with standard library's std::time::Instant.

I'm not sure if it worsened "smoothness" of emulation. It feels the same after this change. I'm not sure that std::time::Instant is as precise as time::precise_time_ns on most systems. However, it all boils down to thread::sleep, which can't be very precise, I think, due to nature of schedulers in standard non-realtime OSes, so nanosecond-grade precision for time measurements is probably not as important.

To get feeling how std::time::Instant works, I ran the following script:

use std::time::Instant;

fn main() {
    let mut t = Instant::now();
    loop {
        println!("{:?}", t.elapsed());
        t = Instant::now();
    }
}

It outputs something like this:

73ns
41ns
41ns
75ns
42ns
42ns
76ns
43ns
41ns
74ns
44ns
44ns
75ns
41ns
42ns
77ns
41ns
41ns

So probably quite precise on my system (Mac OS). Not tested on Linux and Windows.

@kolen
Copy link
Contributor Author

kolen commented Apr 9, 2019

Relevant issue: rust-lang/rust#32626

On Linux, both functions seems to use the same syscall: time, std

@kolen
Copy link
Contributor Author

kolen commented Apr 10, 2019

I compared implementations of precise_time_ns and Instant::now, and for unices, Mac OS and Windows they use the same system calls, so with high certainty time crate can be replaced with Instant from standard library.

@pacmancoder
Copy link
Collaborator

Thanks! I'll merge that.

@pacmancoder pacmancoder merged commit 2d890bd into rustzx:master Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants