公平なベンチマークの記述
両方の言語で同じ処理の時間を測定します
「公平なベンチマークの記述」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why Benchmark at All?
To prove Mojo is faster, you measure it. A benchmark times the exact same task in both languages so the numbers actually mean something. 📊
Same Task, Both Sides
A fair test runs identical work in Python and Mojo. If the algorithms differ, you compare ideas, not languages, and the result is meaningless.
Pick One Workload
Choose a single, clear workload, like summing a million numbers. A focused task is easy to repeat and easy to reason about.
fn sum_to(n: Int) -> Int:
var total = 0
for i in range(n):
total += i
return totalTime the Work, Not Setup
Start the clock right before the work and stop it right after. Timing file loading or imports hides the real compute cost.
from time import now
var start = now()Measure Elapsed Time
Subtract the start from the end to get elapsed time. That single number is what you will compare across the two languages.
var start = now()
# ...work...
var elapsed = now() - startRun It Many Times
One run can be noisy. Repeat the task many times and average, so a random hiccup does not decide your result.
for trial in range(10):
var t = now()
sum_to(1_000_000)Warm Up First
The first run is often slow due to caching and startup. Do a quick warmup run and ignore it before timing for real.
Use a Big Enough Input
Tiny inputs finish too fast to measure. Pick an input large enough that the work takes a meaningful, steady amount of time.
Avoid Dead-Code Removal
If a result is never used, the compiler may delete the work. Print or keep the output so the timed code actually runs.
var r = sum_to(1_000_000)
print(r)Same Machine, Same Conditions
Run both versions on the same machine with nothing heavy in the background. Different hardware ruins any comparison.
Report It Clearly
Write down the input size, number of runs, and the average time. A clear report lets anyone trust and repeat your benchmark.
Quick Check
Think about what makes a comparison trustworthy.
Recap
A fair benchmark times the same work on the same machine, warms up, repeats, and reports clearly. Now the speedup you measure is real. 🎯
よくある質問
「公平なベンチマークの記述」レッスンは無料ですか?
はい。「公平なベンチマークの記述」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。
「公平なベンチマークの記述」で何を学びますか?
両方の言語で同じ処理の時間を測定します ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Mojo Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「公平なベンチマークの記述」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMojo Academyレッスンでコードを書いて実行できますか?
はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 公平なベンチマークの記述
- fnと型が高速化につながる理由
- 数値を正しく読み取る
- Mojoらしいコーディング習慣