liveBook · Manning

Performance

As explained in Coding with AI

The degree to which software executes efficiently in terms of time and computational-resource use.

Performance describes how efficiently software runs in time and computational-resource use. Compare alternative implementations, then test and inspect the generated code before adopting it. section 2.5.3

Timing two text-cleaning functions

Time clean_text1 and clean_text2 on the same file, run the comparison several times, and use the observed result to choose an implementation. Neither function is slow, but clean_text2 appears faster. Treat that result as evidence for this task, not as a substitute for testing, profiling, and debugging. section 2.5.3

def clean_text1(text):
    """Converts the text to lowercase and removes punctuation"""
    text = text.lower()
    punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
    for character in punctuation:
        text = text.replace(character, '')
    return text
def clean_text2(text):
  """Converts the text to lowercase and removes punctuation"""
  # convert to lowercase
  text = text.lower()
  # remove punctuation
  punctuation = ['.', ',', ';', ':', "'", '"', '!', '?', '-', '(', ')']
  for punc in punctuation:
      text = text.replace(punc, '')
  return text

Compare the two punctuation-removal implementations whose execution speed is measured. section 2.5.3

How Coding with AI covers it

How deep it goes
Demonstrates repeated elapsed-time checks and selection, stopping short of a formal benchmarking treatment.
Examples
Uses two punctuation-cleaning functions, a text file, elapsed-time output, and a faster-method selection.
What it assumes
Assumes enough Python knowledge to inspect functions and timing code, while reinforcing testing, profiling, and debugging from practice.
What you can do after
Diagnose performance differences by timing competing Python functions and verifying the resulting code before use.
How it connects
Connects performance with testing, profiling, debugging, code review, and Python implementation choices.

Also explained in

Compare how 40 books explain performance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.