Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions Makefile

This file was deleted.

1 change: 0 additions & 1 deletion benchmark/benches/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const SEED: u64 = 123456789;
const PRECISIONS: [usize; 4] = [0, 1, 5, 10];

// TODO: add benches with other crates
// TODO: try other bench created (CPU counters)

fn bench_conversions(c: &mut Criterion) {
let mut group = c.benchmark_group("[ExtendedFloat<f64>]");
Expand Down
3 changes: 3 additions & 0 deletions benchmark_iai_callgrind/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[profile.bench]
debug = true
strip = false
20 changes: 20 additions & 0 deletions benchmark_iai_callgrind/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "extended_float_benchmarks_iai_callgrind"
version = "0.1.0"
edition = "2024"
authors = ["Ivan Gureev"]
license = "MIT"

[dev-dependencies]
extended_float = { path = "../" }
iai-callgrind = "0.14.0"
rand = "^0.9"

[[bench]]
name = "conversions"
path = "benches/conversions.rs"
harness = false

[profile.release]
lto = true # enable link-time optimisation for faster runtime, but slower compile time
opt-level = 3 # maximum optimisation level for faster runtime, but slower compile time
30 changes: 30 additions & 0 deletions benchmark_iai_callgrind/benches/common/files.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;

pub fn read_lines_from_file<P>(filename: P) -> io::Result<Vec<Vec<u8>>>
where
P: AsRef<Path>,
{
let file = File::open(filename)?;
let buf_reader = io::BufReader::new(file);
let mut data = Vec::new();

for line in buf_reader.lines() {
let line = line?;
data.push(line.into_bytes());
}

Ok(data)
}

pub fn read_file_as_strings<P>(filename: P) -> io::Result<Vec<String>>
where
P: AsRef<Path>,
{
let file_data = read_lines_from_file(filename)?;
Ok(file_data
.iter()
.map(|bytes| String::from_utf8(bytes.clone()).expect("invalid UTF-8"))
.collect())
}
2 changes: 2 additions & 0 deletions benchmark_iai_callgrind/benches/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod files;

66 changes: 66 additions & 0 deletions benchmark_iai_callgrind/benches/conversions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use std::hint::black_box;

mod common;
use common::files::read_file_as_strings;
use extended_float::types::ExtendedFloat;
use iai_callgrind::{LibraryBenchmarkConfig, library_benchmark, library_benchmark_group, main};

#[library_benchmark]
#[bench::zero("0")]
#[bench::zero_2("0.0")]
#[bench::size_1("1.2")]
#[bench::size_3("123.456")]
#[bench::size_5("12345.67890")]
#[bench::size_10("12345.1234567890")]
fn from_str_simple(input: &str) -> ExtendedFloat<f64> {
black_box(input.parse::<ExtendedFloat<f64>>().unwrap())
}

fn setup_from_file_100_k_sum(path: &str) -> Vec<String> {
read_file_as_strings(path).expect("failed to read data file")
}

#[library_benchmark]
#[bench::from_file_100_k_sum(
args = ("test_data/prices.log"),
setup = setup_from_file_100_k_sum
)]
fn bench_parse_file_sum(lines: Vec<String>) -> ExtendedFloat<f64> {
let mut sum = ExtendedFloat::<f64>::default();
for line in black_box(&lines) {
let x: ExtendedFloat<f64> = black_box(line.parse().unwrap());
sum = black_box(sum + x);
}
black_box(sum)
}

fn setup_from_file_100_k_allocate(path: &str) -> (Vec<String>, Vec<ExtendedFloat<f64>>) {
let lines = read_file_as_strings(path).expect("failed to read data file");
let values = vec![ExtendedFloat::<f64>::default(); lines.len()];
(lines, values)
}

#[library_benchmark]
#[bench::from_file_100_k_allocate(
args = ("test_data/prices.log"),
setup = setup_from_file_100_k_allocate
)]
fn bench_parse_file_allocate(
data: (Vec<String>, Vec<ExtendedFloat<f64>>),
) -> Vec<ExtendedFloat<f64>> {
let (lines, mut values) = data;
for (i, line) in black_box(&lines).iter().enumerate() {
values[i] = black_box(line.parse::<ExtendedFloat<f64>>().unwrap());
}
black_box(values)
}

library_benchmark_group!(
name = from_str_group;
benchmarks = from_str_simple, bench_parse_file_sum, bench_parse_file_allocate
);

main!(
config = LibraryBenchmarkConfig::default().callgrind_args(["collect-jumps=yes"]);
library_benchmark_groups = from_str_group
);
Loading
Loading