0Pricing
Mojo Academy · レッスン

計測とベンチマークツール

最適化する前に測定します

「計測とベンチマークツール」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Measure Before You Optimize

Never guess where time goes. You first measure your code, because the slow part is rarely the part you expected. ⏱️

The time Module

Mojo ships a time module with helpers to read the clock. It is your simplest tool for timing a block of work.

from time import now

Reading the Clock

The now function returns the current time in nanoseconds. Capture it just before and just after the work you want to measure.

var start = now()
# ...work...
var end = now()

Computing Elapsed Time

Subtract start from end to get the elapsed nanoseconds. Divide to convert into milliseconds or seconds for readable output.

var elapsed_ns = end - start
var ms = elapsed_ns / 1_000_000

Wall Clock vs Work

Wrap only the code you care about. If you also time setup or printing, that noise hides the real compute cost you are chasing.

Use the benchmark Module

For serious numbers, Mojo offers a benchmark module that runs your code many times and reports a stable average automatically.

from benchmark import keep

Keep Results Alive

The keep function tells the compiler a value really matters. Without it, dead-code removal may delete the work you meant to time.

var r = compute()
keep(r)

Repeat for Stable Numbers

One run is noisy from caches and the OS. Running many iterations and averaging gives a number you can actually trust.

Warm Up the Code

The first run is often slow due to cold caches and startup. A short warmup you discard makes later timings reflect steady-state speed.

Pick a Meaningful Input

Tiny inputs finish too fast to measure well. Choose an input big enough that the work takes a steady, measurable amount of time.

Time Consistently

Always benchmark on the same machine with little running in the background. Stable conditions keep one run comparable to the next.

Quick Check

Think about why we time code at all.

Recap

You learned to measure first: read now from the time module, use benchmark with keep, warm up, repeat, and time steady work. 🎯

よくある質問

「計測とベンチマークツール」レッスンは無料ですか?

はい。「計測とベンチマークツール」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと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フィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 計測とベンチマークツール
  2. 本当のボトルネックを見つける
  3. 重要な部分を最適化する
  4. プロファイルレポートの読み方
← Mojo Academyに戻る