Skip to content

Commit 9d5955d

Browse files
committed
Add recipes for listing and running benchmarks
1 parent 4f118a5 commit 9d5955d

8 files changed

Lines changed: 145 additions & 4 deletions

File tree

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@ BIN_DIR ?= $(NODE_MODULES)/.bin
5959
# Define the top-level folder name containing source files:
6060
SOURCE_FOLDER ?= lib
6161

62-
# Define the folder name for test files:
62+
# Define the folder name convention for test files:
6363
TESTS_FOLDER ?= test
6464

65-
# Define the folder name for test fixtures:
65+
# Define the folder name convention for test fixtures:
6666
TESTS_FIXTURES_FOLDER ?= test/fixtures
6767

68-
# Define the folder name for examples files:
68+
# Define the folder name convention for examples files:
6969
EXAMPLES_FOLDER ?= examples
7070

71+
# Define the folder name convention for benchmark files:
72+
BENCHMARKS_FOLDER ?= benchmark
73+
7174
# Define whether delete operations should be safe (i.e., deleted items are sent to trash, rather than permanently deleted):
7275
SAFE_DELETE ?= false
7376

tools/make/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ include $(TOOLS_MAKE_LIB_DIR)/test-cov/Makefile
3737
include $(TOOLS_MAKE_LIB_DIR)/test-browsers/Makefile
3838
include $(TOOLS_MAKE_LIB_DIR)/test-ci/Makefile
3939
include $(TOOLS_MAKE_LIB_DIR)/coverage-service/Makefile
40+
include $(TOOLS_MAKE_LIB_DIR)/benchmark/Makefile
4041
include $(TOOLS_MAKE_LIB_DIR)/examples/Makefile
4142
include $(TOOLS_MAKE_LIB_DIR)/docs/Makefile
4243
include $(TOOLS_MAKE_LIB_DIR)/debug/Makefile

tools/make/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,28 @@ To filter based on a file path,
164164
$ make TESTS_FIXTURES_FILTER=.*/math/special/.* list-tests-fixtures
165165
```
166166

167+
##### Benchmarks
168+
169+
To list all benchmark files,
170+
171+
``` bash
172+
$ make list-benchmarks
173+
```
174+
175+
To filter based on a file name or pattern,
176+
177+
``` bash
178+
# List only the main benchmark files...
179+
$ make BENCHMARKS_PATTERN=benchmark.js list-benchmarks
180+
```
181+
182+
To filter based on a file path,
183+
184+
``` bash
185+
# List only benchmark files in for base special math functions...
186+
$ make BENCHMARKS_FILTER=.*/math/base/special/.* list-benchmarks
187+
```
188+
167189
##### Examples
168190

169191
To list all examples files,
@@ -291,6 +313,23 @@ $ make TESTS_FILTER=.*/\@stdlib/utils/.* test-view-browsers
291313

292314
===
293315

316+
#### Benchmarks
317+
318+
To run benchmarks,
319+
320+
``` bash
321+
$ make benchmark
322+
```
323+
324+
To limit which benchmarks are run, use the same environment variables recognized by `list-benchmarks`.
325+
326+
``` bash
327+
# Run only the benchmarks for base special math functions...
328+
$ make BENCHMARKS_FILTER=.*/math/base/special/.* BENCHMARKS_PATTERN=benchmark.js benchmark
329+
```
330+
331+
===
332+
294333
#### Documentation
295334

296335
To generate documentation from [JSDoc][jsdoc] source code comments,
@@ -357,7 +396,9 @@ $ make check-deps
357396

358397

359398
<!-- <links> -->
399+
360400
[make]: https://www.gnu.org/software/make/manual/make.html#Introduction
361401
[jsdoc]: http://usejsdoc.org/
402+
362403
<!-- </links> -->
363404

tools/make/lib/benchmark/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# DEPENDENCIES #
3+
4+
include $(TOOLS_MAKE_LIB_DIR)/benchmark/javascript.mk
5+
6+
7+
# TARGETS #
8+
9+
# Run benchmarks.
10+
#
11+
# This target runs benchmarks.
12+
13+
benchmark: benchmark-javascript
14+
15+
.PHONY: benchmark
16+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# VARIABLES #
3+
4+
# Define the command for `node`:
5+
NODE ?= node
6+
7+
8+
# TARGETS #
9+
10+
# Run JavaScript benchmarks.
11+
#
12+
# This target runs a list of JavaScript benchmarks in sequential order. Note that we assume the benchmarks can be run using Node.js.
13+
14+
benchmark-javascript: $(NODE_MODULES)
15+
for file in $(BENCHMARKS); do \
16+
echo ""; \
17+
echo "Running benchmark: $$file"; \
18+
$(NODE) $$file || exit 1; \
19+
done
20+
21+
.PHONY: benchmark-javascript

tools/make/lib/find/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ TESTS_FIXTURES_PATTERN ?= *.*
2525
# Define a filepath pattern for test fixture files:
2626
TESTS_FIXTURES_FILTER ?= .*/.*
2727

28+
# Define a filename pattern for benchmark files:
29+
BENCHMARKS_PATTERN ?= benchmark*.js
30+
31+
# Define a filepath pattern for benchmark files:
32+
BENCHMARKS_FILTER ?= .*/.*
33+
2834
# Define a filename pattern for example files:
2935
EXAMPLES_PATTERN ?= *.js
3036

@@ -47,6 +53,7 @@ include $(TOOLS_MAKE_LIB_DIR)/find/files.mk
4753
include $(TOOLS_MAKE_LIB_DIR)/find/sources.mk
4854
include $(TOOLS_MAKE_LIB_DIR)/find/tests.mk
4955
include $(TOOLS_MAKE_LIB_DIR)/find/tests-fixtures.mk
56+
include $(TOOLS_MAKE_LIB_DIR)/find/benchmarks.mk
5057
include $(TOOLS_MAKE_LIB_DIR)/find/examples.mk
5158
include $(TOOLS_MAKE_LIB_DIR)/find/markdown.mk
5259
include $(TOOLS_MAKE_LIB_DIR)/find/modules.mk

tools/make/lib/find/benchmarks.mk

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
# VARIABLES #
3+
4+
# Define the folder name for benchmarks files:
5+
BENCHMARKS_FOLDER ?= benchmark
6+
7+
# Determine the host kernel:
8+
KERNEL ?= $(shell uname -s)
9+
10+
# On Mac OSX, in order to use `|` and other regular expression operators, we need to use enhanced regular expression syntax (-E); see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man7/re_format.7.html#//apple_ref/doc/man/7/re_format.
11+
12+
ifeq ($(KERNEL), Darwin)
13+
find_kernel_prefix := -E
14+
else
15+
find_kernel_prefix :=
16+
endif
17+
18+
# Define a suffix for pretty printing results as a list:
19+
find_print_benchmarks_list := -exec printf '%s\n' {} \;
20+
21+
# Define the command flags:
22+
FIND_BENCHMARKS_FLAGS ?= \
23+
-name "$(BENCHMARKS_PATTERN)" \
24+
-path "$(ROOT_DIR)/**/$(BENCHMARKS_FOLDER)/**" \
25+
-regex "$(BENCHMARKS_FILTER)" \
26+
-not -path "$(ROOT_DIR)/.*" \
27+
-not -path "$(NODE_MODULES)/*" \
28+
-not -path "$(TOOLS_DIR)/*" \
29+
-not -path "$(BUILD_DIR)/*" \
30+
-not -path "$(REPORTS_DIR)/*"
31+
32+
33+
ifneq ($(KERNEL), Darwin)
34+
FIND_BENCHMARKS_FLAGS := -regextype posix-extended $(FIND_BENCHMARKS_FLAGS)
35+
endif
36+
37+
# Define the list of benchmark files:
38+
BENCHMARKS ?= $(shell find $(find_kernel_prefix) $(ROOT_DIR) $(FIND_BENCHMARKS_FLAGS))
39+
40+
41+
# TARGETS #
42+
43+
# List benchmark files.
44+
#
45+
# This target prints a newline-delimited list of benchmark files.
46+
47+
list-benchmarks:
48+
@find $(find_kernel_prefix) $(ROOT_DIR) $(FIND_BENCHMARKS_FLAGS) $(find_print_benchmarks_list)
49+
50+
.PHONY: list-benchmarks

tools/make/usage.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Usage: make <cmd>
77
make list-sources List all source files (excluding examples and tests).
88
make list-examples List all example files.
99
make list-tests List all test files.
10-
make list-tests-fixtures List all test fixture files.
10+
make list-tests-fixtures List all test fixture files.
11+
make list-benchmarks List all benchmark files.
1112
make list-files List files.
1213
make list-modules List all modules.
1314
make examples Run examples.
@@ -17,6 +18,7 @@ Usage: make <cmd>
1718
make test-browsers Run tests in a local web browser.
1819
make view-cov View the most recent code coverage report.
1920
make view-browser-tests View browser tests in a local web browser.
21+
make benchmark Run benchmarks.
2022
make src-docs Generate source documentation.
2123
make view-src-docs View source documentation.
2224
make lint Lint files.

0 commit comments

Comments
 (0)