Development timer macros - in Rust.

Wringing performance out of available hardware is something that we like to do.

Having written that we’ve never encountered a customer who cared about energy consumption, ever. The green stuff is for the marketing department and PR, apparently. (Really.)

The point.

Perhaps it was Lord Kelvin who said “If you can not measure it, you can not improve it.” - perhaps not true in all cases, but for software development it seems like a pretty good mantra. To this end, we have our own little library of Rust macros and CLI utilities for timing processes, getting system information and writing it to the CLI.

When doing POC and development, we import this library and the basics that we need are there for us. We can see what makes a difference simply. Because we have the system specs as well, we can make sure we’re comparing oranges with oranges on each run.

Timer Macros

Timers.rs offers:

Here’s an example:


    use wolves_cli_helper::{verbose::say, verbose::announce, TC, TD, TE, TR};
    use console::style;

    // Shout out the system specifications
    announce(None);

    // Create a timer
    let tinsert: String = "InsertingRecords".to_string();
    let mut loadtimer = TC!(&tinsert); // Timer create.

    // Do very important work . . . .
    let rows = a_function_that_takes_an_awfully_long_time();

    // End the timer here
    TE!(&tinsert, loadtimer); // End the timer.

    // Display the duration and rate
    say(format!(
        "Inserted {:?} records in {:?} ms at {:?} /s",
        style(rows).green(),
        style(TD!(&tinsert, loadtimer)).green(),
        style(TR!(&tinsert, loadtimer, rows.try_into()?)).green()
    ).as_str())?;

This output shows the duration and rate for reading 20,000 .bz2 compressed files, extracting hundreds of files archived tweets from each one and coalescing the top 5 users with the greatest number of followers.

FYI, the NFS drivers on MacOS appear to be very. very slow compared to Linux. There will be more on this work coming soon.

alt text

Integrating the library.

Just add the GitHub repo to your Cargo.toml file:

wolves-cli-helper = { git = "https://github.com/WebTargetLtd/wolves-cli-helper" }

That’s it. Done.