title: What is the easiest way to time a function call for testing purposes?
body: <p>So I'm still kinda green in Rust, but coming from Python I find this scenario very confusing in general.</p>
  <p>I like Python because it's very easy if you want to time a block of code or just a function call:</p>
  <pre class="lang-py prettyprint-override"><code>print(timeit('a = &quot;hee hee la le dah&quot;; my_awesome_fn()', number = 1_000, globals=globals()))
  </code></pre>
  <p>Then just call <code>python script.py</code> or better yet just use the green &quot;run&quot; button in the IDE and you can call the script. But I'm having trouble finding functional equivalent in Rust.</p>
  <p>I know there is concept in Rust ecosystem called benchmarking and some libs like <code>criterion</code> exist for this purpose. The problem is that I know nothing about advanced math and statistics (can treat me like a clueless moron essentially) and I doubt I can benefit a lot from a framework or harness such as this.</p>
  <p>So I am simply just curious how can I use <code>tests</code> in cargo to test a block of code in Rust or better yet even a function call.</p>
  <p>For example assume I have similar function in rust that I want to call multiple times and then check how does performance change etc:</p>
  <pre><code>pub fn my_awesome_fn() {
      trace!(&quot;getting ready to do something cool...&quot;);
      std::thread::sleep(std::time::Duration::from_millis(500));
      info!(&quot;finished!&quot;);
  }
  </code></pre>
  <p>how can I simply just time this func <code>my_awesome_fn</code> in rust? I guess i'm looking for an equivalent like <code>timeit</code> in python or something similar. Ideally it should be striaghtforward to use and assume i don't know anything about what I'm doing. I'm curious if there's an existing library or framework I can leverage for this purposes.</p>