In this approach, we'll find out how to most efficiently calculate the RNA Transcription.

The approaches page lists two idiomatic approaches to this exercise:

  1. Using translate() with maketrans() approach
  2. Using dictionary look-up with join() approach

Benchmarks

To benchmark the approaches, we wrote a small benchmark application using the timeit library.

translate maketrans: 2.502872000914067e-07
dictionary join:     1.0920033999718725e-06

At about 250 nanoseconds, the translate() with maketrans() approach is more than four times faster than the dictionary with join() approach, which takes about 1092 nanoseconds.

4th Sep 2024 · Found it useful?