Skip to content
Merged
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ test-ui: node_modules
env PLAYWRIGHT_BASE_URL=$(SANDBOX_URL) \
$(NPX) playwright test --config test/ui/playwright.config.js

.PHONY: benchmark
benchmark:
./benchmark/index.sh $(OUTPUT)/dist/bin/sourcemeta-one-index

.PHONY: sandbox-index
sandbox-index: compile
$(PREFIX)/bin/sourcemeta-one-index \
Expand Down
90 changes: 65 additions & 25 deletions benchmark/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,32 @@ else
fi

nanoseconds() {
if [ "$IS_DARWIN" = "1" ]; then
if [ "$IS_DARWIN" = "1" ]
then
perl -MTime::HiRes=time -e 'printf "%d\n", time * 1000000000'
else
date +%s%N
fi
}

generate_schema() {
cat << EOF > "$TMP/schemas/$1.json"
{
"\$schema": "http://json-schema.org/draft-07/schema#",
"\$id": "https://example.com/$1"
}
EOF
}

measure_add_one() {
generate_schema "$1"
START="$(nanoseconds)"
"$INDEX" --skip-banner "$TMP/one.json" "$TMP/output" >&2
END="$(nanoseconds)"
echo "$(( (END - START) / 1000000 ))"
}

INDEX="$1"
TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT
Expand All @@ -34,38 +53,59 @@ cat << EOF > "$TMP/one.json"
}
EOF

# First run: the schemas directory has a single schema
mkdir "$TMP/schemas"

cat << 'EOF' > "$TMP/schemas/first.json"
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/first"
}
EOF
# Measure adding one schema to an empty registry
echo "Measuring: add one schema (0 existing)..." >&2
RESULT_0_TO_1="$(measure_add_one "schema-0")"
echo " Result: ${RESULT_0_TO_1}ms" >&2

"$1" --skip-banner "$TMP/one.json" "$TMP/output" 2> /dev/null
# Fill up to 100 schemas
echo "Filling registry to 100 schemas..." >&2
index=1
while [ "$index" -lt 100 ]
do
generate_schema "schema-$index"
index=$((index + 1))
done
"$INDEX" --skip-banner "$TMP/one.json" "$TMP/output" >&2

# Second run: add another schema and measure the rebuild
cat << 'EOF' > "$TMP/schemas/second.json"
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/second"
}
EOF
# Measure adding one schema to a 100-schema registry
echo "Measuring: add one schema (100 existing)..." >&2
RESULT_100_TO_101="$(measure_add_one "schema-100")"
echo " Result: ${RESULT_100_TO_101}ms" >&2

START="$(nanoseconds)"
"$1" --skip-banner "$TMP/one.json" "$TMP/output" 2> /dev/null
END="$(nanoseconds)"
# Fill up to 1000 schemas
echo "Filling registry to 1000 schemas..." >&2
index=101
while [ "$index" -lt 1000 ]
do
generate_schema "schema-$index"
index=$((index + 1))
done
"$INDEX" --skip-banner "$TMP/one.json" "$TMP/output" >&2

ELAPSED="$(( (END - START) / 1000000 ))"
# Measure adding one schema to a 1000-schema registry
echo "Measuring: add one schema (1000 existing)..." >&2
RESULT_1000_TO_1001="$(measure_add_one "schema-1000")"
echo " Result: ${RESULT_1000_TO_1001}ms" >&2

cat << EOF
[
{
"name": "Add One Schema",
"unit": "ms",
"value": $ELAPSED
}
{
"name": "Add one schema (0 existing)",
"unit": "ms",
"value": $RESULT_0_TO_1
},
{
"name": "Add one schema (100 existing)",
"unit": "ms",
"value": $RESULT_100_TO_101
},
{
"name": "Add one schema (1000 existing)",
"unit": "ms",
"value": $RESULT_1000_TO_1001
}
]
EOF