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

Implements a performance tracker #43

Merged
merged 5 commits into from
Apr 29, 2023

Conversation

GStefanowich
Copy link
Contributor

A start of a fix for #42. Seemed like a fun challenge to take a stab at

Added a --debug CLI flag to enable debug mode, it'll pass around an IPerformanceStack (which is meant to be similar to a Stack (eg; a Stacktrace)).

The interface mainly adds two methods

// Create a new nested stack
IPerformanceStack CreateStack(string name);

// Add a new measured step in the current stack
void Step(string name);

When --debug is not enabled, it'll pass around an empty object which just calls void methods, so no accidental overhead performing normally:

static readonly IPerformanceStack DEFAULT = new DefaultPerformanceStack();

private sealed class DefaultPerformanceStack : IPerformanceStack {
    /// <inheritdoc />
    public IPerformanceStack CreateStack(string name)
        => this;

    /// <inheritdoc />
    public void Step(string name) {}

    public void Log() {}

    void IDisposable.Dispose() {}
}

The new logger output with debug on is:

Extraction time: 2,052ms
Addresses extracted: 16
Read lines total: 285,130
Read lines rate: 138,952/s

 - Read file x6 | Took 2,049ms (at ~342ms per)
   - Read line x356,412 | Took 2,018ms (at ~6μs per)
   - Run regex x356,411 | Took 1,117ms (at ~3μs per)
     - Check length    x308,890 | Took 337ms (at ~1μs per)
     - Capture string  x308,890 | Took 73ms (at ~0μs per)
     - Filter invalids x308,890 | Took 127ms (at ~0μs per)
     - Validate domain x285,130 | Took 90ms (at ~0μs per)

Read file and Run regex have nested stacks under them (Just some nice formatting). This way the amount of time spent on each action can be seen, and the average time for each iteration (default: microseconds).


Also fixed an issue where --help was actually ---help and --version was actually ---version

@GStefanowich
Copy link
Contributor Author

@troyhunt Merge conflict resolved if you want to merge

You can do some indepth testing on what parts of the code are slowest since you can throw some data leaks at it

@troyhunt troyhunt merged commit 9b9e026 into HaveIBeenPwned:main Apr 29, 2023
@GStefanowich GStefanowich deleted the performance_tracker branch April 29, 2023 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants