A stopwatch library for Rust. Used to time things.

Overview

rust-stopwatch

This is a simple module used to time things in Rust.

Build Status

Usage

To use, add the following line to Cargo.toml under [dependencies]:

stopwatch = "0.0.7"

or alternatively,

stopwatch = { git = "https://github.com/ellisonch/rust-stopwatch.git" }

Example

extern crate stopwatch;
use stopwatch::{Stopwatch};
// ...
let sw = Stopwatch::start_new();
// do something that takes some time
println!("Thing took {}ms", sw.elapsed_ms());

Methods

fn new() -> Stopwatch
fn start_new() -> Stopwatch
fn start(&mut self)
fn stop(&mut self)
fn reset(&mut self)
fn restart(&mut self)
fn is_running(&self) -> bool
fn elapsed(&self) -> Duration
fn elapsed_ms(&self) -> i64
Comments
  • Add split methods

    Add split methods

    I think this should be the implementation for the feature request in issue #12.

    I also added some tests and doc comments to existing and new methods. The usage is as follows:

    let mut sw = Stopwatch::start_new();
    // --> do something for three seconds
    sw.elapsed_split_ms(); // should return ~3000
    // --> do some more for two seconds
    sw.elapsed_split_ms(); // should return ~2000
    sw.elapsed_ms(); //should return ~5000
    

    Maybe this example could also be added to the doc comments.

    I'm not sure with the name of the methods, I just used split because the button on the webpage I mentioned in #12 was labeled Split.

    What do you think? Please tell me if anything is wrong. This is my first real pull request to an existing external project.

    opened by FelixHaller 2
  • Add dependency line to README

    Add dependency line to README

    It seems common practice to show the Cargo.toml line in rust repos. Adding that, so the lazy of us don't have to go an extra round trip to find the latest version.

    opened by johshoff 2
  • Fix imports

    Fix imports

    "time" and "num" aren't part of the standard library any more, so the project wasn't compiling. I fixed those imports and everything works fine now.

    opened by AaronJRubin 2
  • Publish new version to crates.io

    Publish new version to crates.io

    HI!

    As far as I know issue #5 is already done, but since I'm getting the same error message when I'm using dependency "*" in my Cargo.toml I think there needs to be a new versio uploaded (?) I'm getting version 0.5 which seems too old. I'm expecting 0.6 Can you please publish a new build?

    opened by chrissssss 1
  • Compilation issue

    Compilation issue

    the Stopwatch wasn't compiling with cargo cargo 0.2.0-nightly (efb482d 2015-04-30) (built 2015-04-29)

    src/lib.rs:9:5: 9:26 error: unresolved import std::num::ToPrimitive. There is no ToPrimitive in std::num src/lib.rs:9 use std::num::ToPrimitive; ^~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error Could not compile stopwatch.

    opened by hareendran 1
  • Install is not possible

    Install is not possible

    I have added this as a dependency to my Cargo-file like this:

    [dependencies]
    stopwatch = "0.0.3"
    

    Trying to do a cargo build results in the following error:

        Updating registry `https://github.com/rust-lang/crates.io-index`
     Downloading gcc v0.1.5
     Downloading time v0.1.12
     Downloading stopwatch v0.0.3
       Compiling gcc v0.1.5
       Compiling time v0.1.12
       Compiling stopwatch v0.0.3
    /home/nobbz/.cargo/registry/src/github.com-1ecc6299db9ec823/stopwatch-0.0.3/src/lib.rs:35:28: 35:36 error: type `u64` does not implement any method in scope named `to_i64`
    /home/nobbz/.cargo/registry/src/github.com-1ecc6299db9ec823/stopwatch-0.0.3/src/lib.rs:35   let diff_i = match diff_u.to_i64() {
                                                                                                                              ^~~~~~~~
    error: aborting due to previous error
    Could not compile `stopwatch`.
    

    edit I use rust version rustc 1.0.0-nightly (170c4399e 2015-01-14 00:41:55 +0000)

    opened by NobbZ 1
  • More time-tracking methods

    More time-tracking methods

    Hello!

    Thanks for the crate :)

    I did add some methods for more convenient elapsed time tracking:

    • in nanoseconds;
    • in seconds;
    • in minutes;
    • in hours.

    Also, it was updated Display trait implementation with respect of new methods. It convert milliseconds to more human readable format. For example, if there was elapsed 3500 ms, the next code:

    let sw = Stopwatch::start_new();
    println!("{}", sw);
    

    will print: 3s 500ms.

    And if there was elapsed, for example, 500 ms it will print 500ms (if there was spent minutes or even hours this will display them).

    opened by MikhailKravets 0
  • Derive Clone trait for Stopwatch

    Derive Clone trait for Stopwatch

    Built against: rustc 1.0.0-nightly (be9bd7c93 2015-04-05) (built 2015-04-06)

    • Copy now requires Clone - rust-lang/rust#23860
    • Fixed warnings in tests, remove usage of old_io

    Thanks!

    opened by justinlatimer 0
  • Document methods a little better?

    Document methods a little better?

    • start_new() is presumably a convenience method for doing new() + start() in one call?
    • Difference between reset() and restart()?

    Just from a glance of the the minimal info presented to a user, those were two things that stood out. Compared to using the standard Instant from Rust, I was interested in time taken between calls, turned out that was added as a feature that never arrived to crates.io.

    As a user, I can try the methods out individually, but knowing in advance would have been nicer. Below is for any other user not wanting to try the API out or look over source:

    • restart(): Continues running the timer but restarting from 0.
    • reset(): Stops the timer and resets the value to 0.
    • stop(): Stops the timer but doesn't reset the value.
    • new(): Creates a timer but does not start it. restart() will also initiate the timer like start(). Must be mutable to track time.
    • start_new(): Creates the timer and starts it. Does not need to be mutable for elapsed time tracking.

    For lap functionality where you want to get the elapsed time since your previous measurement, you need a mutable stopwatch and to call sw.restart() between your two sw.elapsed_ms() calls. Alternatively if you source the crate from github instead of crates.io, you can use sw.elapsed_split_ms()

    opened by polarathene 0
  • Relicense under dual MIT/Apache-2.0

    Relicense under dual MIT/Apache-2.0

    This issue was automatically generated. Feel free to close without ceremony if you do not agree with re-licensing or if it is not possible for other reasons. Respond to @cmr with any questions or concerns, or pop over to #rust-offtopic on IRC to discuss.

    You're receiving this because someone (perhaps the project maintainer) published a crates.io package with the license as "MIT" xor "Apache-2.0" and the repository field pointing here.

    TL;DR the Rust ecosystem is largely Apache-2.0. Being available under that license is good for interoperation. The MIT license as an add-on can be nice for GPLv2 projects to use your code.

    Why?

    The MIT license requires reproducing countless copies of the same copyright header with different names in the copyright field, for every MIT library in use. The Apache license does not have this drawback. However, this is not the primary motivation for me creating these issues. The Apache license also has protections from patent trolls and an explicit contribution licensing clause. However, the Apache license is incompatible with GPLv2. This is why Rust is dual-licensed as MIT/Apache (the "primary" license being Apache, MIT only for GPLv2 compat), and doing so would be wise for this project. This also makes this crate suitable for inclusion and unrestricted sharing in the Rust standard distribution and other projects using dual MIT/Apache, such as my personal ulterior motive, the Robigalia project.

    Some ask, "Does this really apply to binary redistributions? Does MIT really require reproducing the whole thing?" I'm not a lawyer, and I can't give legal advice, but some Google Android apps include open source attributions using this interpretation. Others also agree with it. But, again, the copyright notice redistribution is not the primary motivation for the dual-licensing. It's stronger protections to licensees and better interoperation with the wider Rust ecosystem.

    How?

    To do this, get explicit approval from each contributor of copyrightable work (as not all contributions qualify for copyright, due to not being a "creative work", e.g. a typo fix) and then add the following to your README:

    ## License
    
    Licensed under either of
    
     * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
     * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
    
    at your option.
    
    ### Contribution
    
    Unless you explicitly state otherwise, any contribution intentionally submitted
    for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
    additional terms or conditions.
    

    and in your license headers, if you have them, use the following boilerplate (based on that used in Rust):

    // Copyright 2016 rust-stopwatch developers
    //
    // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
    // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
    // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
    // option. This file may not be copied, modified, or distributed
    // except according to those terms.
    

    It's commonly asked whether license headers are required. I'm not comfortable making an official recommendation either way, but the Apache license recommends it in their appendix on how to use the license.

    Be sure to add the relevant LICENSE-{MIT,APACHE} files. You can copy these from the Rust repo for a plain-text version.

    And don't forget to update the license metadata in your Cargo.toml to:

    license = "MIT/Apache-2.0"
    

    I'll be going through projects which agree to be relicensed and have approval by the necessary contributors and doing this changes, so feel free to leave the heavy lifting to me!

    Contributor checkoff

    To agree to relicensing, comment with :

    I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option.
    

    Or, if you're a contributor, you can check the box in this repo next to your name. My scripts will pick this exact phrase up and check your checkbox, but I'll come through and manually review this issue later as well.

    • [ ] @ellisonch
    • [ ] @justinlatimer
    • [ ] @AaronJRubin
    opened by emberian 0
Owner
Chucky Ellison
Chucky Ellison
Statistics-driven benchmarking library for Rust

Criterion.rs Statistics-driven Microbenchmarking in Rust Getting Started | User Guide | Master API Docs | Released API Docs | Changelog | | Criterion.

Brook Heisler 3.1k Jan 8, 2023
A Rust implementation of the PCP instrumentation API

hornet hornet is a Performance Co-Pilot (PCP) Memory Mapped Values (MMV) instrumentation library written in Rust. Contents What is PCP MMV instrumenta

Performance Co-Pilot 33 Sep 15, 2022
An intrusive flamegraph profiling tool for rust.

FLAME A cool flamegraph library for rust Flamegraphs are a great way to view profiling information. At a glance, they give you information about how m

null 631 Jan 3, 2023
Experimental one-shot benchmarking/profiling harness for Rust

Iai Experimental One-shot Benchmark Framework in Rust Getting Started | User Guide | Released API Docs | Changelog Iai is an experimental benchmarking

Brook Heisler 409 Dec 25, 2022
Benchmark for Rust and humans

bma-benchmark Benchmark for Rust and humans What is this for I like testing different libraries, crates and algorithms. I do benchmarks on prototypes

Altertech 11 Jan 17, 2022
Rust wrapper for COCO benchmark functions.

Coco Rust bindings for the COCO Numerical Black-Box Optimization Benchmarking Framework. See https://github.com/numbbo/coco and https://numbbo.github.

Leopold Luley 1 Nov 15, 2022
A http server benchmark tool written in rust 🦀

rsb - rust benchmark rsb is a http server benchmark tool written in rust. The development of this tool is mainly inspired by the bombardier project, a

Michael 45 Apr 10, 2023
Stopwatch lib for rust. Start, pause, reset and lap like any stopwatch.

Chronometer Stopwatch lib for rust. Start, pause, reset and lap like any stopwatch. Nothing special I'm just learning rust. Getting Started Add this l

Naoufel Berrada 2 Sep 29, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
A clock app in terminal written in Rust, supports local clock, timer and stopwatch.

clock-tui (tclock) A clock app in terminal. It support the following modes: Clock Timer Stopwatch Countdown Usage Install Install excutable by cargo:

Jimmy 14 Dec 20, 2022
Rust library for putting things in a grid

rust-term-grid This library arranges textual data in a grid format suitable for fixed-width fonts, using an algorithm to minimise the amount of space

Benjamin Sago 61 Nov 4, 2022
A collection of small Rust programs for doing weird things

This is a repo of small programs, proof of concepts, or templates written in Rust that relate in some way to hacking and/or CTF. I think Rust is real

d3npa 22 Nov 9, 2022
Host These Things Please - a basic http server for hosting a folder fast and simply

http Host These Things Please - a basic HTTP server for hosting a folder fast and simply Selected features See the manpage for full list. Symlinks fol

thecoshman 367 Dec 23, 2022
A Discord bot for lichess and Rosen related things

liro Liro is a Discord bot that follows in the footsteps of Lichess-discord-bot, without necessarily aiming to replace it. The main pain point that th

Sebastian Lauwers 5 Feb 16, 2022
Scouty is a command-line interface (CLI) to keep an eye on substrate-based chains and hook things up

scouty is a command-line interface (CLI) to keep an eye on substrate-based chains and hook things up

TurboFlakes 15 Aug 6, 2022
Brutally simple command line app for jotting things down

jot Brutally simple command line app for jotting things down. About jot lets you get things down before you forget, without fiddling folders, naming,

Alexander Alexandrov 1 Apr 8, 2022
A collection (eventually) of examples that use some non-beginner things.

nannou examples A collection (eventually) of examples that use some non-beginner things. Right now the only example combines nannou's standard draw AP

Alexis Andre 22 Oct 21, 2022
Giddy up! Things are going to be wild.

Jocky - For controlling your horses Current Idea The idea is essentially to have a custom directory that writes immutable segments, this means only 2

Harrison Burt 3 Jan 7, 2023
Work out how far apart things should be (very quickly)

Kern determiner Work out how far apart things should be (very quickly) kerndeterminer is a Rust-based library for determining a kern value between two

Simon Cozens 10 Oct 29, 2022
Tool to copy things!

zp zp is a cli command to copy the contents of the source file or of the std output buffer to the clipboard. To use the zp, simply open your terminal

Gokul 26 Apr 22, 2023