Skip to content

feat: add timing information to ic debugger#238

Open
rishabh1024 wants to merge 3 commits into
gruns:masterfrom
rishabh1024:feature/timer-186
Open

feat: add timing information to ic debugger#238
rishabh1024 wants to merge 3 commits into
gruns:masterfrom
rishabh1024:feature/timer-186

Conversation

@rishabh1024

Copy link
Copy Markdown

Summary

Implements timing functionality as a requested in issue #186
Adds ic.timer which can be used as:

  • Decorator: @ic.timer - prints function execution time
  • Context manager: with ic.timer: - prints block execution time

Example Output

@ic.timer
def slow_function():
    time.sleep(1)

slow_function()
# ic| slow_function took 1.00s

with ic.timer:
    time.sleep(0.5)
# 500.12ms

Co-authored-by: Cursor <cursoragent@cursor.com>
@Jakeroid

Copy link
Copy Markdown
Collaborator

@rishabh1024 Hey,

Thank you for adding a PR. Could you show an example how it would work together with calling ic(). My assumption was we are going to have something like:

with ic.timer:
    ic(foo())

@rishabh1024

Copy link
Copy Markdown
Author

Hey @Jakeroid,

The timer would work this way as well. Execution remains the same I just wrapped it into the context manager.

Sample Code:


def print_range_of_numbers(start: int, end: int):
    for i in range(start, end):
        ic(i)

with ic.timer:
    print_range_of_numbers(1, 10)```

    
Output:
python3 -m icecream.test_timer
ic| i: 1
ic| i: 2
ic| i: 3
ic| i: 4
ic| i: 5
ic| i: 6
ic| i: 7
ic| i: 8
ic| i: 9
27.87ms

@rishabh1024

Copy link
Copy Markdown
Author

Hey @Jakeroid, did you get a chance to look at the code?

@Jakeroid

Copy link
Copy Markdown
Collaborator

@rishabh1024 I haven't yet, but I'll take a look soon.

@rishabh1024

Copy link
Copy Markdown
Author

Thanks @Jakeroid, Looking forward to you review!

@Jakeroid

Jakeroid commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

@rishabh1024

Hey,

I've run CI workflows and it looks like MyPy one has an error. Do you think you will have time to check and fix it?

mypy: commands[0]> mypy icecream
icecream/icecream.py:567: error: Function is missing a return type annotation  [no-untyped-def]
icecream/icecream.py:569: error: Function is missing a return type annotation  [no-untyped-def]
icecream/icecream.py:583: error: Function is missing a type annotation  [no-untyped-def]
icecream/icecream.py:586: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
Found 3 errors in 1 file (checked 5 source files)
mypy: exit 1 (1.70 seconds) /home/runner/work/icecream/icecream> mypy icecream pid=2267
  mypy: FAIL code 1 (11.26=setup[9.56]+cmd[1.70] seconds)
  evaluation failed :( (11.29 seconds)

@rishabh1024

Copy link
Copy Markdown
Author

Hey @Jakeroid,

Yes, I can fix the issue and revise the commit.

Thanks

@rishabh1024 rishabh1024 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the type hints to fix the CI workflow error.

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