Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stdlib] [benchmarks] [NFC] Fix benchmarking for public repo #4054

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions mojo/stdlib/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@ internally.

## How to run the benchmarks

If you want to just compile and run all of the benchmarks as-is,
there is a script provided [here](../../stdlib/scripts/run-benchmarks.sh).
This script builds the open source `stdlib.mojopkg` and then executes
all of the benchmarks sequentially. The script also allows specifying a
subdirectory or a file to run.

Running e.g. `magic run mojo run stdlib/benchmarks/collections/bench_dict.mojo`
makes the linker use the existing branch that the compiler is on. If you wish to
test changes you are making on the current branch, remove the `-t` flag on top
of the benchmark file (`# RUN: %mojo-no-debug %s -t`) then run:
`magic run stdlib/scripts/run-benchmarks.sh
stdlib/benchmarks/collections/bench_dict.mojo`.
Remember to replace the `-t` flag again before pushing any code.
Running e.g. `magic run benchmarks ./stdlib/benchmarks/collections` runs every
file in the directory sequentially using the build based on the current branch.
It can also run one file when specified.

## How to write effective benchmarks

Expand Down
2 changes: 0 additions & 2 deletions mojo/stdlib/benchmarks/algorithm/bench_elementwise.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo-no-debug %s -t
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove
# the -t flag. Remember to replace it again before pushing any code.

from sys import simdwidthof

Expand Down
2 changes: 0 additions & 2 deletions mojo/stdlib/benchmarks/builtin/bench_int.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo-no-debug %s -t
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove
# the -t flag. Remember to replace it again before pushing any code.

from benchmark import Bench, BenchConfig, Bencher, BenchId

Expand Down
2 changes: 0 additions & 2 deletions mojo/stdlib/benchmarks/builtin/bench_sort.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo-no-debug %s -t
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove
# the -t flag. Remember to replace it again before pushing any code.

from random import *

Expand Down
2 changes: 0 additions & 2 deletions mojo/stdlib/benchmarks/collections/bench_dict.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo-no-debug %s -t
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove
# the -t flag. Remember to replace it again before pushing any code.

from collections import Dict, Optional
from collections.dict import DictEntry
Expand Down
2 changes: 0 additions & 2 deletions mojo/stdlib/benchmarks/collections/bench_string.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo-no-debug %s -t
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove
# the -t flag. Remember to replace it again before pushing any code.

from collections import Dict, Optional
from collections.string import String
Expand Down
2 changes: 0 additions & 2 deletions mojo/stdlib/benchmarks/hashlib/bench_hash.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo-no-debug %s -t
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove
# the -t flag. Remember to replace it again before pushing any code.

from hashlib._ahash import (
MULTIPLE,
Expand Down
2 changes: 0 additions & 2 deletions mojo/stdlib/benchmarks/math/bench_math.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo-no-debug %s -t
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove
# the -t flag. Remember to replace it again before pushing any code.

from math import *
from random import *
Expand Down
2 changes: 0 additions & 2 deletions mojo/stdlib/benchmarks/utils/bench_formatter.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo-no-debug %s -t
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove
# the -t flag. Remember to replace it again before pushing any code.

from collections.string.string_slice import _memchr, _memmem
from sys import simdwidthof
Expand Down
2 changes: 0 additions & 2 deletions mojo/stdlib/benchmarks/utils/bench_memmem.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: %mojo-no-debug %s -t
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove
# the -t flag. Remember to replace it again before pushing any code.

from math import align_down
from collections.string.string_slice import _memchr, _memmem
Expand Down
13 changes: 13 additions & 0 deletions mojo/stdlib/scripts/run-benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,18 @@ if [[ $# -gt 0 ]]; then
BENCHMARK_PATH=$1
fi

# HACK: this is an absolutely horrible hack, please fix this
if [[ -z "${_START_MODULAR_INCLUDED+x}" ]]; then
# save the original stdlib
mv -f ${REPO_ROOT}/.magic/envs/default/lib/mojo/stdlib.mojopkg ${BUILD_DIR}/og_stdlib.mojopkg
# copy the newly built stdlib
cp -f ${BUILD_DIR}/stdlib.mojopkg ${REPO_ROOT}/.magic/envs/default/lib/mojo/stdlib.mojopkg
fi

# Run the benchmarks sequentially
lit --succinct --show-all --workers 1 ${BENCHMARK_PATH}

if [[ -z "${_START_MODULAR_INCLUDED+x}" ]]; then
# return the original stdlib
mv -f ${BUILD_DIR}/og_stdlib.mojopkg ${REPO_ROOT}/.magic/envs/default/lib/mojo/stdlib.mojopkg
fi