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

[REQUEST] Time formatting repr from perfplot.bench() output #157

Open
gabrielfu opened this issue Oct 13, 2022 · 0 comments
Open

[REQUEST] Time formatting repr from perfplot.bench() output #157

gabrielfu opened this issue Oct 13, 2022 · 0 comments

Comments

@gabrielfu
Copy link

gabrielfu commented Oct 13, 2022

Consider posting in https://github.com/nschloe/perfplot/discussions for feedback before raising a feature request.

How would you improve perfplot?

Format the time in perfplot.bench() output in a manner similar to timeit module.

Proposal:
Adding a new function:

def format_time(dt: float, precision: int=3):
    """Formats time to unit. Taken from `timeit` module."""
    units = {"nsec": 1e-9, "usec": 1e-6, "msec": 1e-3, "sec": 1.0}
    scales = [(scale, unit) for unit, scale in units.items()]
    scales.sort(reverse=True)
    for scale, unit in scales:
        if dt >= scale:
            break
    return "%.*g %s" % (precision, dt / scale, unit)

Then, formatting it in PerfplotData.__repr__(self)

lst = [str(n)] + [str(tt) for tt in t]

-            lst = [str(n)] + [str(tt) for tt in t]
+            lst = [str(n)] + [format_time(tt) for tt in t]

What problem does it solved for you?

Right now the output from perfplot.bench() is not very readable:

Code:

out = perfplot.bench(...)
print(out)

Current output:

Overall ---------------------------------------- 100% 0:00:00
Kernels ----------------------------------------   0% 0:00:02
┌────┬────────────────────────┬────────────────────────┬────────────────────────┐
│ n  │ kernel1                │ kernel2                │ kernel3                │
├────┼────────────────────────┼────────────────────────┼────────────────────────┤
│ 4  │ 0.00010070000000000001 │ 4.2600000000000005e-05 │ 1.8000000000000001e-06 │
│ 8  │ 0.0002924              │ 0.0006585              │ 7.8e-06                │
│ 16 │ 0.0010366000000000002  │ 0.0052959              │ 4.1e-05                │
└────┴────────────────────────┴────────────────────────┴────────────────────────┘

Proposed output:

Overall ---------------------------------------- 100% 0:00:00
Kernels ----------------------------------------   0% -:--:--
┌────┬───────────┬───────────┬───────────┐
│ n  │ kernel1   │ kernel2   │ kernel3   │
├────┼───────────┼───────────┼───────────┤
│ 4  │ 158 usec  │ 55.2 usec │ 18.1 usec │
│ 8  │ 386 usec  │ 865 usec  │ 10.9 usec │
│ 16 │ 1.43 msec │ 10.8 msec │ 57.5 usec │
└────┴───────────┴───────────┴───────────┘

Did I help

If I was able to resolve your problem, consider sponsoring my work on perfplot, or buy me a coffee to say thanks.

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

No branches or pull requests

1 participant