{"library":"monotonic","code":"import time\n\n# For compatibility across Python versions, prefer this pattern:\ntry:\n    from time import monotonic as get_monotonic_time_fn\nexcept ImportError:\n    # Fallback for Python 2 and Python < 3.3 using the 'monotonic' package\n    from monotonic import monotonic as get_monotonic_time_fn\n\nprint('Starting a monotonic timer...')\nstart_time = get_monotonic_time_fn()\n\n# Simulate some work\ntime.sleep(2.5)\n\nend_time = get_monotonic_time_fn()\nelapsed_time = end_time - start_time\n\nprint(f'Elapsed time: {elapsed_time:.3f} seconds')\n","lang":"python","description":"This quickstart demonstrates how to use the `monotonic` function to measure elapsed time, ensuring that clock adjustments do not affect the duration measurement. It includes a robust import pattern for compatibility across Python 2 and Python 3.3+.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}