Skip to content

Commit

Permalink
Use Program::from_file in hyperthreading crate (#1685)
Browse files Browse the repository at this point in the history
* Read programs from file in hyperthreading crate

* Fix code

* Fix path

* fmt
  • Loading branch information
fmoletta authored Mar 21, 2024
1 parent bf7d707 commit 72f0bad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/hyper_threading/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ keywords.workspace = true


[dependencies]
cairo-vm = { workspace = true }
cairo-vm = { workspace = true, features = ["std"] }
rayon = "1.9.0"
tracing = "0.1.40"
55 changes: 28 additions & 27 deletions examples/hyper_threading/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,43 @@ use cairo_vm::{
types::program::Program,
};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use std::path::Path;

// Define include_bytes_relative macro to prepend a relative path to the file names
macro_rules! include_bytes_relative {
// Define build_filename macro to prepend a relative path to the file names
macro_rules! build_filename {
($fname:expr) => {
include_bytes!(concat!("../../../cairo_programs/benchmarks/", $fname))
format!("cairo_programs/benchmarks/{}", $fname)
};
}

fn main() {
let mut programs = Vec::new();

let programs_bytes: [Vec<u8>; 18] = [
include_bytes_relative!("big_factorial.json").to_vec(),
include_bytes_relative!("big_fibonacci.json").to_vec(),
include_bytes_relative!("blake2s_integration_benchmark.json").to_vec(),
include_bytes_relative!("compare_arrays_200000.json").to_vec(),
include_bytes_relative!("dict_integration_benchmark.json").to_vec(),
include_bytes_relative!("field_arithmetic_get_square_benchmark.json").to_vec(),
include_bytes_relative!("integration_builtins.json").to_vec(),
include_bytes_relative!("keccak_integration_benchmark.json").to_vec(),
include_bytes_relative!("linear_search.json").to_vec(),
include_bytes_relative!("math_cmp_and_pow_integration_benchmark.json").to_vec(),
include_bytes_relative!("math_integration_benchmark.json").to_vec(),
include_bytes_relative!("memory_integration_benchmark.json").to_vec(),
include_bytes_relative!("operations_with_data_structures_benchmarks.json").to_vec(),
include_bytes_relative!("pedersen.json").to_vec(),
include_bytes_relative!("poseidon_integration_benchmark.json").to_vec(),
include_bytes_relative!("secp_integration_benchmark.json").to_vec(),
include_bytes_relative!("set_integration_benchmark.json").to_vec(),
include_bytes_relative!("uint256_integration_benchmark.json").to_vec(),
let program_filenames: [String; 18] = [
build_filename!("big_factorial.json"),
build_filename!("big_fibonacci.json"),
build_filename!("blake2s_integration_benchmark.json"),
build_filename!("compare_arrays_200000.json"),
build_filename!("dict_integration_benchmark.json"),
build_filename!("field_arithmetic_get_square_benchmark.json"),
build_filename!("integration_builtins.json"),
build_filename!("keccak_integration_benchmark.json"),
build_filename!("linear_search.json"),
build_filename!("math_cmp_and_pow_integration_benchmark.json"),
build_filename!("math_integration_benchmark.json"),
build_filename!("memory_integration_benchmark.json"),
build_filename!("operations_with_data_structures_benchmarks.json"),
build_filename!("pedersen.json"),
build_filename!("poseidon_integration_benchmark.json"),
build_filename!("secp_integration_benchmark.json"),
build_filename!("set_integration_benchmark.json"),
build_filename!("uint256_integration_benchmark.json"),
];

for bytes in &programs_bytes {
programs.push(Program::from_bytes(bytes.as_slice(), Some("main")).unwrap())
let n_programs = &program_filenames.len();

for filename in program_filenames {
programs.push(Program::from_file(Path::new(&filename), Some("main")).unwrap())
}

let start_time = std::time::Instant::now();
Expand All @@ -61,7 +64,5 @@ fn main() {
});
let elapsed = start_time.elapsed();

let programs_len: &usize = &programs_bytes.clone().len();

tracing::info!(%programs_len, ?elapsed, "Finished");
tracing::info!(%n_programs, ?elapsed, "Finished");
}

0 comments on commit 72f0bad

Please sign in to comment.