{"id":18473928,"url":"https://github.com/ohsayan/devtimer","last_synced_at":"2025-04-08T12:32:05.791Z","repository":{"id":57618641,"uuid":"220806528","full_name":"ohsayan/devtimer","owner":"ohsayan","description":"Operation benchmarking and timing library for Rust","archived":false,"fork":false,"pushed_at":"2022-07-26T21:02:18.000Z","size":54,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T19:14:05.451Z","etag":null,"topics":["benchmarking","rust","rust-crate","rust-lang","testing","time","timer"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ohsayan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-10T15:05:39.000Z","updated_at":"2023-01-12T19:36:49.000Z","dependencies_parsed_at":"2022-09-16T19:01:40.246Z","dependency_job_id":null,"html_url":"https://github.com/ohsayan/devtimer","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fdevtimer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fdevtimer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fdevtimer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fdevtimer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohsayan","download_url":"https://codeload.github.com/ohsayan/devtimer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247842727,"owners_count":21005338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmarking","rust","rust-crate","rust-lang","testing","time","timer"],"created_at":"2024-11-06T10:27:12.224Z","updated_at":"2025-04-08T12:32:05.520Z","avatar_url":"https://github.com/ohsayan.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Devtimer [![Build Status](https://travis-ci.com/ohsayan/devtimer.svg?branch=master)](https://travis-ci.com/ohsayan/devtimer) [![Crates.io](https://img.shields.io/crates/v/devtimer)](https://crates.io/crates/devtimer) [![Crates.io](https://img.shields.io/badge/docs.rs-Docs-blue)](https://docs.rs/devtimer) [![Crates.io](https://img.shields.io/crates/d/devtimer)](https://crates.io/crates/devtimer) [![Crates.io](https://img.shields.io/crates/l/devtimer)](./LICENSE)\nThe **compact** yet **complete** benchmarking suite for Rust. Period.\n\n# Rationale\n\nI've seen many, _many_ benchmarking tools. However, no one realizes that we need simplicity to simplify development and increase productivity. \n`devtimer` provides a very _compact_ yet _complete_ benchmarking suite for code written in Rust. \nIt makes use of the standard library _only_ to provide benchmark operations. \nYou can either use it for benchmarking a single operation or you can use it for\nrunning an operation multiple times and finding the min, max and average \nexecution times. Since this crate has no external dependencies, it is small, \nfast and does exactly what it claims to. Happy benchmarking!\n\nNeed help migrating from an older version? See [the changelog](./CHANGELOG.md).\n\n# Usage\n\nAdd this to your `cargo.toml` :\n\n``` toml\ndevtimer = \"*\"\n```\n\nThen add this line to your source file (i.e `main.rs` or `lib.rs` or where you need to use it):\n\n``` rust\nuse devtimer::DevTime;\n```\n\n# Example usage\n\n## Simple usage\n\nLet's say there are two functions called `very_long_operation()` and `another_op()` that take a very long time to execute. Then we can time it's execution as shown below:\n\n``` rust\nfn main() {\n    let mut timer = DevTime::new_simple();\n    timer.start();\n    very_long_operation();\n    timer.stop();\n    println!(\"The operation took: {} ns\", timer.time_in_nanos().unwrap());\n    // You can keep re-using the timer for other operations\n    timer.start(); // this resets the timer and starts it again\n    another_op();\n    timer.stop();\n    println!(\"The operation took: {} secs\", timer.time_in_secs().unwrap());\n    println!(\"The operation took: {} milliseconds\", timer.time_in_millis().unwrap());\n    println!(\"The operation took: {} microseconds\", timer.time_in_micros().unwrap());\n    println!(\"The operation took: {} ns\", timer.time_in_nanos().unwrap());\n\n    // With version 1.1.0 and upwards\n    timer.start_after(\u0026std::time::Duration::from_secs(2));\n    // The timer will start after two seconds\n    // Do some huge operation now\n    timer.stop();\n    println!(\"The operation took: {} nanoseconds\", devtimer.time_in_nanos().unwrap());\n}\n```\n\n## Example: Benchmarking\n\n``` rust\nuse devtimer::run_benchmark;\nfn main() {\n  // We will simulate a long operation by std::thread::sleep()\n  // Run 10 iterations for the test\n  let bench_result = run_benchmark(10, |_| {\n    // Fake a long running operation\n    std::thread::sleep(std::time::Duration::from_secs(1);\n  });\n  bench_result.print_stats();\n}\n```\n\n#### Advanced Benchmarking\n\nThe `run_benchmark()` function also provides a `usize` that can be used, say if you want to get something from an array to do the test. For example:\n\n```rust \nrun_benchmark(100, |n| {\n  do_action(data_source[n]);\n});\n```\n\n## Example: Tagged timers\n\n``` rust\nuse devtimer::DevTime;\nfn main() {\n  let mut cmplx = DevTime::new_complex();\n  // Create a timer with tag `timer-1` \n  cmplx.create_timer(\"timer-1\").unwrap();\n  cmplx.start_timer(\"timer-1\").unwrap();\n  // Simulate a slow operation\n  std::thread::sleep(std::time::Duration::from_secs(1));\n  cmplx.stop_timer(\"timer-1\").unwrap();\n  \n  // Create a timer with tag `cool-timer` \n  cmplx.create_timer(\"cool-timer\").unwrap();\n  cmplx.start_timer(\"cool-timer\").unwrap();\n  // Simulate a slow operation\n  std::thread::sleep(std::time::Duration::from_secs(2));\n  cmplx.stop_timer(\"cool-timer\").unwrap();\n\n  // We can output a benchmark in this way\n  println!(\" `cool-timer` took: {}\", cmplx.time_in_micros(\"cool-timer\").unwrap());\n\n  // Or we can iterate through all timers\n  for (tname, timer) in cmplx.iter() {\n    println!(\"{} - {} ns\", tname, timer.time_in_micros().unwrap());\n  }\n\n  // Or we can print results in the default '{timername} - {time} ns' format\n  cmplx.print_stats();\n}\n```\n\nTiming functions available (names are self explanatory):\n\n* `time_in_secs()` -\u003e Returns the number of seconds the operation took\n* `time_in_millis()` -\u003e Returns the number of milliseconds the operation took\n* `time_in_micros()` -\u003e Returns the number of microseconds the operation took\n* `time_in_nanos()` -\u003e Return the number of nanoseconds the operation took\n\nSee the full docs [here](https://docs.rs/devtimer).\n\n# License\n\nThis project is licensed under the [Apache-2.0 License](./LICENSE). Keep coding and benchmarking!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohsayan%2Fdevtimer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohsayan%2Fdevtimer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohsayan%2Fdevtimer/lists"}