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

Stabilize Duration::span as-is? #1243

Closed
SimonSapin opened this issue Aug 7, 2015 · 5 comments
Closed

Stabilize Duration::span as-is? #1243

SimonSapin opened this issue Aug 7, 2015 · 5 comments

Comments

@SimonSapin
Copy link
Contributor

std::time currently contains:

impl Duration {
    /// Runs a closure, returning the duration of time it took to run the
    /// closure.
    #[unstable(feature = "duration_span",
               reason = "unsure if this is the right API or whether it should \
                         wait for a more general \"moment in time\" \
                         abstraction")]
    pub fn span<F>(f: F) -> Duration where F: FnOnce() {
        let start = SteadyTime::now();
        f();
        &SteadyTime::now() - &start
    }
}

I’d like to stabilize this method unchanged. Even if a "moment in time" abstraction exists, doing the let start = now(); do stuff; now() - start dance gets tedious very quickly and a closure-based Duration::span method would still be valuable.

@Stebalien
Copy link
Contributor

I strongly disagree; IMO, this should really be a free-standing function (e.g. std::time::timeit). The time a function takes to run has nothing to do with time itself. This is kind of like adding a usize::count<I: Iterator>(i: I) -> usize function.

@SimonSapin
Copy link
Contributor Author

That’s a good point, it probably should be moved. Though I’d still like to have one expression rather than three statements.

@gsingh93
Copy link

gsingh93 commented Aug 7, 2015

+1 for std::time::timeit.

@Stebalien
Copy link
Contributor

Though I’d still like to have one expression rather than three statements.

Definitely.

@SimonSapin
Copy link
Contributor Author

Closing in favor of rust-lang/rust#27799.

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

No branches or pull requests

3 participants