from timer import Timer
import time

def example_function():
    """示例函数：模拟一些耗时操作"""
    time.sleep(1)  # 模拟耗时1秒的操作

def main():
    # 方式1：使用start/stop方法
    timer = Timer()
    timer.start()
    example_function()
    timer.stop()
    print(f"方式1 - 函数运行时间: {timer.elapsed():.3f} 秒")
    
    # 方式2：使用with语句（更优雅的方式）
    with Timer() as timer:
        example_function()
    print(f"方式2 - 函数运行时间: {timer.elapsed():.3f} 秒")

if __name__ == '__main__':    
    main()