Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move bench-utils into std, and simplify workspace #29

Merged
merged 6 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 0 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,5 @@ jobs:

- name: ark-std
run: |
cd std
cargo build -p ark-std --no-default-features --target thumbv6m-none-eabi
cargo check --examples -p ark-std --no-default-features --target thumbv6m-none-eabi
cd ..

- name: bench-utils
run: |
cd bench-utils
cargo build -p bench-utils --no-default-features --target thumbv6m-none-eabi
cargo check --examples -p bench-utils --no-default-features --target thumbv6m-none-eabi
cd ..
33 changes: 28 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
[workspace]
[package]
name = "ark-std"
version = "0.1.0"
authors = [ "arkworks contributors" ]
description = "A library for no_std compatibility"
homepage = "https://arkworks.rs"
repository = "https://github.com/arkworks-rs/utils"
documentation = "https://docs.rs/ark-std/"
keywords = [ "no_std" ]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2018"

members = [
"bench-utils",
"std",
]
[dependencies]
rand = { version = "0.7", default-features = false }
# rand = { version = "0.8", default-features = false, features = ["std_rng"] }
rand_xorshift = "0.2"
# rand_xorshift = "0.3"
rayon = { version = "1", optional = true }

colored = { version = "2", optional = true }


[features]
default = [ "std" ]
std = []
parallel = [ "rayon", "std" ]
print-trace = [ "std", "colored" ]

[profile.release]
Pratyush marked this conversation as resolved.
Show resolved Hide resolved
opt-level = 3
Expand Down
23 changes: 0 additions & 23 deletions bench-utils/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion bench-utils/LICENSE-APACHE

This file was deleted.

1 change: 0 additions & 1 deletion bench-utils/LICENSE-MIT

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions std/src/lib.rs → src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub use std::*;
mod rand_helper;
pub use rand_helper::*;

pub mod perf_trace;

/// Returns the ceiling of the base-2 logarithm of `x`.
///
/// ```
Expand Down
60 changes: 44 additions & 16 deletions bench-utils/src/lib.rs → src/perf_trace.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
#![no_std]
#![allow(unused_imports)]

//! This module contains macros for logging to stdout a trace of wall-clock time required
//! to execute annotated code. One can use this code as follows:
//! ```
//! use ark_std::{start_timer, end_timer};
//! let start = start_timer!(|| "Addition of two integers");
//! let c = 5 + 7;
//! end_timer!(start);
//! ```
//! The foregoing code should log the following to stdout.
//! ```text
//! Start: Addition of two integers
//! End: Addition of two integers... 1ns
//! ```
//!
//! These macros can be arbitrarily nested, and the nested nature is made apparent
//! in the output. For example, the following snippet:
//! ```
//! use ark_std::{start_timer, end_timer};
//! let start = start_timer!(|| "Addition of two integers");
//! let start2 = start_timer!(|| "Inner");
//! let c = 5 + 7;
//! end_timer!(start2);
//! end_timer!(start);
//! ```
//! should print out the following:
//! ```text
//! Start: Addition of two integers
//! Start: Inner
//! End: Inner ... 1ns
//! End: Addition of two integers... 1ns
//! ```
//!
//! Additionally, one can use the `add_to_trace` macro to log additional context
//! in the output.
pub use self::inner::*;

// This isn't needed except for use in the print-trace code below
#[cfg(feature = "std")]
extern crate std;

#[macro_use]
#[cfg(feature = "print-trace")]
pub mod inner {
Expand All @@ -31,7 +59,7 @@ pub mod inner {
#[macro_export]
macro_rules! start_timer {
($msg:expr) => {{
use $crate::inner::{
use $crate::perf_trace::inner::{
compute_indent, AtomicUsize, Colorize, Instant, Ordering, ToString, NUM_INDENT,
PAD_CHAR,
};
Expand All @@ -41,9 +69,9 @@ pub mod inner {
let indent_amount = 2 * NUM_INDENT.fetch_add(0, Ordering::Relaxed);
let indent = compute_indent(indent_amount);

$crate::println!("{}{:8} {}", indent, start_info, msg);
$crate::perf_trace::println!("{}{:8} {}", indent, start_info, msg);
NUM_INDENT.fetch_add(1, Ordering::Relaxed);
$crate::TimerInfo {
$crate::perf_trace::TimerInfo {
msg: msg.to_string(),
time: Instant::now(),
}
Expand All @@ -56,7 +84,7 @@ pub mod inner {
end_timer!($time, || "");
}};
($time:expr, $msg:expr) => {{
use $crate::inner::{
use $crate::perf_trace::inner::{
compute_indent, format, AtomicUsize, Colorize, Instant, Ordering, ToString,
NUM_INDENT, PAD_CHAR,
};
Expand Down Expand Up @@ -88,7 +116,7 @@ pub mod inner {

// Todo: Recursively ensure that *entire* string is of appropriate
// width (not just message).
$crate::println!(
$crate::perf_trace::println!(
"{}{:8} {:.<pad$}{}",
indent,
end_info,
Expand All @@ -102,7 +130,7 @@ pub mod inner {
#[macro_export]
macro_rules! add_to_trace {
($title:expr, $msg:expr) => {{
use $crate::{
use $crate::perf_trace::{
compute_indent, compute_indent_whitespace, format, AtomicUsize, Colorize, Instant,
Ordering, ToString, NUM_INDENT, PAD_CHAR,
};
Expand All @@ -125,9 +153,9 @@ pub mod inner {

// Todo: Recursively ensure that *entire* string is of appropriate
// width (not just message).
$crate::println!("{}{}", start_indent, start_msg);
$crate::println!("{}{}", msg_indent, final_message,);
$crate::println!("{}{}", start_indent, end_msg);
$crate::perf_trace::println!("{}{}", start_indent, start_msg);
$crate::perf_trace::println!("{}{}", msg_indent, final_message,);
$crate::perf_trace::println!("{}{}", start_indent, end_msg);
}};
}

Expand Down Expand Up @@ -156,7 +184,7 @@ mod inner {
#[macro_export]
macro_rules! start_timer {
($msg:expr) => {
$crate::TimerInfo
$crate::perf_trace::TimerInfo
};
}
#[macro_export]
Expand Down
File renamed without changes.
25 changes: 0 additions & 25 deletions std/Cargo.toml

This file was deleted.