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

Suppress line numbers in tock() #12

Closed
kretes opened this issue Nov 16, 2021 · 5 comments
Closed

Suppress line numbers in tock() #12

kretes opened this issue Nov 16, 2021 · 5 comments

Comments

@kretes
Copy link

kretes commented Nov 16, 2021

Hello.

Thanks for your effort on the library, works really nice.

I would like to polish the output a bit - i.e. suppress the line numbers from the tock event, since In some cases they are redundant.
For a :

@ticktick("aaa")
def a():
   pass

I want: [aaaa] 1s200 ms and now I have [aaaa:3-5] 1s200 ms

And for a:

a_clock = tick(name="train batch")
a_clock.tock()

I want: [train batch] 100ms and now I get [train batch:11] 100ms

Rationale:
In the annotation case - this is obvious that a method with decorator will just get a single tock() for every tick - and so there is no need to differentiate the times, and hence it would be best if the output shown would just contain the name passed to @ticktock()

In the manual case - I would say, that this should be user-controlled. I am not sure what the API would be best, but maybe something like tick(single_tock=True) or tock(only=True) that would made the tock() not record any name for the tock and therefore the ouptut might just contain the name passed to tick ?

@victorbenichoux
Copy link
Owner

Hi @kretes

Thanks for the feedback! I have to say that I totally agree with your rationale...

The good news is that what you want to achieve is already achievable from the main branch.
If you install with

pip install git+https://github.com/victorbenichoux/ticktock.git

You can set a format string such as:

from ticktock import tick, set_format

set_format("[{tick_name}] {mean}")

I agree with your comment that there remains confusion on the tick and tock names and their rendering. This is especially true with the function decorator and context manager.

I need to go back and make sure that it is all consistent, which I hoped to do before releasing the package later this week.

Could you check out that it works OK with the set format method? I will keep you posted!

@kretes
Copy link
Author

kretes commented Nov 17, 2021

Thanks!

When using the code from source I can use {tick_name} in the format, that is good and works.
This doesn't solve the decorator scenario fully, since there in https://github.com/victorbenichoux/ticktock/blob/main/ticktock/timer.py#L277 line number is appended to the tick_name.

Still - a solution to control it at the level of tick-tock and not in the format would be beneficial

@victorbenichoux
Copy link
Owner

Thanks again for the feedback.

Bottom line is we have a clear bug with the decorator which I will try and fix soon.

Controlling the format at the tick/tock level is also something that was requested in another issue 😬 . I originally was not convinced but I suppose now is the time to put it in! It should be done shortly, and I will push a new release afterwards!

@victorbenichoux
Copy link
Owner

This is fixed in the current release!

@kretes
Copy link
Author

kretes commented Nov 30, 2021

many thanks. It works as expected if combined with format set to include just tick_name.

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

2 participants