Giter Site home page Giter Site logo

Code timing instrumentation about std HOT 7 OPEN

jon-chuang avatar jon-chuang commented on June 7, 2024
Code timing instrumentation

from std.

Comments (7)

jon-chuang avatar jon-chuang commented on June 7, 2024

Will be included in celo-org/zexe#4 with the following interface:

    let now = timing!();
    dlsd_radixsort(bucket_positions, 8);
    timing_println!(now, "radixsort");

and following output:
--features "timing"

[ radixsort ] 2168us

--features "timing_detailed"

batch_bucketed_add in bucketed_add.rs 50:51 [ radixsort ] 11532us

from std.

jon-chuang avatar jon-chuang commented on June 7, 2024

Code uses macros:


#[macro_export]
macro_rules! timing_println {
    ($now: ident, $string: expr) => {
        #[cfg(feature = "timing")]
        {
            println!("[ {} ] {}us", $string, $now.1.elapsed().as_micros(),);
        }

        #[cfg(feature = "timing_detailed")]
        {
            macro_rules! function {
                () => {{
                    fn f() {}
                    fn type_name_of<T>(_: T) -> &'static str {
                        core::any::type_name::<T>()
                    }
                    let name = type_name_of(f);
                    &name[..name.len() - 3]
                }};
            }
            println!(
                "{} in {} {}:{} [ {} ] {}us",
                String::from(function!()).split("::").last().unwrap(),
                String::from(file!()).split("/").last().unwrap(),
                $now.0,
                line!() - 1,
                $string,
                $now.1.elapsed().as_micros(),
            );
        }
    };
}

#[macro_export]
macro_rules! timing {
    () => {{
        #[cfg(any(feature = "timing", feature = "timing_detailed"))]
        let now = (line!(), std::time::Instant::now());

        #[cfg(not(any(feature = "timing", feature = "timing_detailed")))]
        let now = ();
        now
    }};
}

from std.

jon-chuang avatar jon-chuang commented on June 7, 2024

The next step is to use proc macros to define which specific invocation of a function ought to compile with timing instrumentation using an attribute like

#[timing(on)]
batch_affine_add(..)

#[timing(off)]
batch_affine_double(..)

from std.

Pratyush avatar Pratyush commented on June 7, 2024

This already exists with the bench-utils crate

from std.

jon-chuang avatar jon-chuang commented on June 7, 2024

Hmm I see. Thats cool. I will work on mine a bit and see if we can combine some features. One thing I can do is to identify the function in which the timer is called, so that one can blacklist functions from emiting log msgs

from std.

Pratyush avatar Pratyush commented on June 7, 2024

Longer term I plan to move to infrastructure based on tracing, which would allow similar blacklisting (and has many more features to boot!)

from std.

jon-chuang avatar jon-chuang commented on June 7, 2024

Hmm looks really interesting, looking forward to using tracing!

from std.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.