-
-
Save swarnimarun/620dd57d2bdd3441c0573172fd60997f to your computer and use it in GitHub Desktop.
benchmark results for hello world, pls ensure that terminal itself is not the bottleneck, by redirecting output to a non-busy file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Results | |
# | |
# Macbook M1 Pro 16GB RAM | |
# Chip: M1 Pro | |
# | |
# best of 5: 154 nsec per loop (+/- 10) | |
# | |
# lines printed: `wc -l` | |
# :: 13888889 (yep not so slow are we now haha!) | |
python3 -m timeit "print('Hello, World!')" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(test)] | |
extern crate test; | |
use test::Bencher; | |
#[bench] | |
/// [[benchmark-results]] | |
/// | |
/// Macbook M1 Pro 16GB RAM | |
/// Chip: M1 Pro | |
/// | |
/// 1,342 ns/iter (+/- 150) | |
/// | |
/// lines printed: `wc -l` | |
/// :: 288007 (+/- 50000) | |
fn hello_world(b: &mut Bencher) { | |
b.iter(move || { | |
// With println! bench and test run without output capture | |
// this inflates the result of benchmarking | |
// ensure the use of, `--nocapture` | |
// ```sh | |
// cargo +nightly bench -Z unstable-options -- --nocapture | |
// ``` | |
println!("Hello, World!"); | |
}); | |
} | |
#[bench] | |
/// [[benchmark-results]] | |
/// | |
/// Macbook M1 Pro 16GB RAM | |
/// Chip: M1 Pro | |
/// | |
/// 13 ns/iter (+/- 0) | |
/// | |
/// lines printed: `wc -l` | |
/// :: 460836007 (does it even matter? it's a 3+ GB file) | |
fn better_hello_world(b: &mut Bencher) { | |
use std::io::Write; | |
let stdout = std::io::stdout(); | |
let lock = stdout.lock(); | |
let mut out = std::io::BufWriter::new(lock); | |
b.iter(|| { | |
test::black_box(write!(out, "Hello, World!\n")); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment