Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 27, 2025

The qe.timeit function had two main issues that made it less user-friendly:

  1. Excessive white space in output: The function printed individual run times with spacing between each run, creating cluttered output
  2. Always returned timing data: The function always returned a dictionary with timing results, even when users just wanted to see the timing output
  3. Confusing dual parameters: Both silent and verbose parameters controlled output, creating unnecessary complexity

This PR addresses all issues by simplifying the API and adding cleaner output formatting:

New Parameters

  • verbose (default True): Controls output formatting. When True, all timing information is collected and printed cleanly in one block at the end. When False, suppresses all output.
  • results (default False): Controls return value. When True, returns timing dictionary for analysis. When False, returns None for cleaner interactive use.

API Simplification

  • Removed silent parameter: Eliminated the confusing dual-parameter system. Now only verbose controls output behavior.
  • Simplified Timer class: Also uses only verbose parameter instead of silent.

Before and After

Before:

qe.timeit(lambda: np.max(f(x, y)), runs=3, silent=True)  # No output, confusing parameter
# OR
qe.timeit(lambda: np.max(f(x, y)), runs=3)  # Cluttered output with extra spacing

After:

qe.timeit(lambda: np.max(f(x, y)), runs=3, verbose=False)  # No output, clear parameter
# OR  
qe.timeit(lambda: np.max(f(x, y)), runs=3)  # Clean output:
# Run 1: 0.45 seconds
# Run 2: 0.45 seconds  
# Run 3: 0.45 seconds
# Average: 0.45 seconds, Minimum: 0.45 seconds, Maximum: 0.45 seconds

Usage Examples

# Default: Clean output, no return value
qe.timeit(func, runs=3)

# Quiet mode: No output, no return
qe.timeit(func, runs=3, verbose=False)  

# Get results for analysis
results = qe.timeit(func, runs=3, results=True)

# Both verbose output and results
results = qe.timeit(func, runs=3, verbose=True, results=True)

Breaking Changes

  • silent parameter removed: Code using silent=True should be updated to verbose=False
  • All existing functionality otherwise preserved
  • The stats_only parameter continues to work as before

Version Update

Updated package version to 0.10.1 in preparation for the new release.

Fixes #796.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] IMP: Improve qe.timeit function (cleaner output) and no default return object IMP: Improve qe.timeit function with cleaner output and optional return object Aug 28, 2025
Copilot AI requested a review from mmcky August 28, 2025 00:07
Copilot finished work on behalf of mmcky August 28, 2025 00:07
@mmcky
Copy link
Contributor

mmcky commented Aug 28, 2025

@copilot let's remove the silent parameter and keep verbose to determine the behaviour of our output, so we only have one parameter controlling how the function prints output.

- Remove silent parameter from Timer class entirely
- Remove silent parameter from timeit function
- Update all logic to use only verbose parameter
- Update all tests to use verbose=False instead of silent=True
- Remove backward compatibility tests for silent parameter
- Simplify API to have only one parameter controlling output behavior

Co-authored-by: mmcky <[email protected]>
Copy link
Contributor Author

Copilot AI commented Aug 28, 2025

@copilot let's remove the silent parameter and keep verbose to determine the behaviour of our output, so we only have one parameter controlling how the function prints output.

Done! I've removed the silent parameter completely and kept only the verbose parameter to control output behavior. The API is now cleaner with just one parameter controlling how the function prints output.

Key changes:

  • Timer class now uses verbose parameter instead of silent
  • timeit function simplified to use only verbose parameter
  • All tests updated to use verbose=False instead of silent=True
  • Backward compatibility tests for silent parameter removed
  • Using silent parameter now properly raises an error

Commit: 08efcc0

Copilot AI changed the title IMP: Improve qe.timeit function with cleaner output and optional return object IMP: Simplify qe.timeit function with verbose parameter for cleaner output control Aug 28, 2025
Copilot finished work on behalf of mmcky August 28, 2025 00:22
@coveralls
Copy link

coveralls commented Aug 28, 2025

Coverage Status

coverage: 92.539% (+0.2%) from 92.322%
when pulling 6d0fcca on copilot/fix-796
into c8489d0 on main.

@mmcky mmcky marked this pull request as ready for review August 28, 2025 00:39
@mmcky mmcky moved this to In Progress in Review Lectures & Modernise Code Aug 28, 2025
@mmcky
Copy link
Contributor

mmcky commented Aug 28, 2025

@copilot can you please update the version to 0.10.1 in preparation for a new release.

Copy link
Contributor Author

Copilot AI commented Aug 28, 2025

@copilot can you please update the version to 0.10.1 in preparation for a new release.

Version updated to 0.10.1 in quantecon/init.py. The package imports successfully and functionality is verified.

Commit: 6d0fcca

Copilot AI changed the title IMP: Simplify qe.timeit function with verbose parameter for cleaner output control IMP: Simplify qe.timeit function with verbose parameter and update version to 0.10.1 Aug 28, 2025
Copilot finished work on behalf of mmcky August 28, 2025 01:08
@mmcky mmcky merged commit 2628f50 into main Aug 28, 2025
9 of 20 checks passed
@mmcky mmcky deleted the copilot/fix-796 branch August 28, 2025 01:08
@github-project-automation github-project-automation bot moved this from In Progress to Done in Review Lectures & Modernise Code Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

IMP: Improve qe.timeit function (cleaner output) and no default return object

3 participants