Skip to content

Instantly share code, notes, and snippets.

@roganjoshp
Created September 7, 2025 18:30
Show Gist options
  • Select an option

  • Save roganjoshp/a0a6c0f8ac54dbc29db6f0f4c28058e6 to your computer and use it in GitHub Desktop.

Select an option

Save roganjoshp/a0a6c0f8ac54dbc29db6f0f4c28058e6 to your computer and use it in GitHub Desktop.
import logging
import timeit
logger = logging.getLogger(__name__)
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.INFO)
def as_args():
some_str = "This is some kind of error message reasonably long"
some_other = "And let's throw this in too"
logger.debug("There was: %s with %s", some_str, some_other)
def as_f_str():
some_str = "This is some kind of error message reasonably long"
some_other = "And let's throw this in too"
logger.debug(f"There was: {some_str} with {some_other}")
if __name__ == "__main__":
print(
"As Args 1",
timeit.timeit(
"as_args()",
setup="from __main__ import as_args",
number=10000000,
),
)
print(
"As f-string 1",
timeit.timeit(
"as_f_str()",
setup="from __main__ import as_f_str",
number=10000000,
),
)
print(
"As Args 2",
timeit.timeit(
"as_args()",
setup="from __main__ import as_args",
number=10000000,
),
)
print(
"As f-string 2",
timeit.timeit(
"as_f_str()",
setup="from __main__ import as_f_str",
number=10000000,
),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment