chore: use mitata for benchmarks

This commit is contained in:
skdhg committed 2023-09-16 16:21:47 +05:45
1 parent ca796eb8f0
commit c6dcb75449
13 files changed
+130 -288

No files matched your search

+7
View File
@@ -37,6 +37,7 @@ jobs:
build: |
yarn build --target i686-pc-windows-msvc
yarn test
yarn benchmark
target: i686-pc-windows-msvc
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
@@ -202,6 +203,7 @@ jobs:
yarn build
strip -x *.node
yarn test
yarn benchmark
rm -rf node_modules
rm -rf target
rm -rf .yarn/cache
@@ -248,6 +250,8 @@ jobs:
shell: bash
- name: Test bindings
run: yarn test
- name: Benchmark bindings
run: yarn benchmark
test-linux-x64-gnu-binding:
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
needs:
@@ -280,6 +284,8 @@ jobs:
shell: bash
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
- name: Benchmark bindings
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn benchmark
# test-linux-x64-musl-binding:
# name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
# needs:
@@ -427,6 +433,7 @@ jobs:
run: |
set -e
yarn test
yarn benchmark
ls -la
universal-macOS:
name: Build universal macOS binary
+39 -46
View File
@@ -90,60 +90,53 @@ const decoded = encoder.decode(encoded);
You can use `OpusEncoder` to encode pcm data to opus and decode opus data to pcm format. Stream interface is provided by [@discord-player/opus](https://npm.im/@discord-player/opus) package.
#### Opus Benchmarks
Mediaplex includes benchmarks for the opus encoder/decoder. Here are the results of the benchmarks on a Windows 11 machine with an i7-8700 3.2GHz processor:
#### Opus benchmark with other equivalent libraries
```js
$ yarn benchmark
Running "OpusEncoder Benchmark" suite...
cpu: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
runtime: node v20.6.1 (x64-win32)
mediaplex:
3 538 ops/s, ±0.63% | 15.96% slower
benchmark time (avg) (min … max) p75 p99 p995
------------------------------------------------------------ -----------------------------
• OpusEncoder
------------------------------------------------------------ -----------------------------
mediaplex 282.31 µs/iter (274.4 µs … 746.9 µs) 279.5 µs 378.7 µs 391.3 µs
@discordjs/opus 315.47 µs/iter (310 µs … 460.4 µs) 314.1 µs 384.6 µs 396.8 µs
@evan/opus 304.59 µs/iter (299.9 µs … 483.7 µs) 303.5 µs 357.4 µs 376.9 µs
@evan/opus (wasm) 469.27 µs/iter (440.1 µs … 1.3 ms) 447 µs 964.1 µs 1.03 ms
opusscript 249.68 µs/iter (235.3 µs … 692.1 µs) 240.7 µs 499.5 µs 551.3 µs
opusscript (no wasm) 4.01 ms/iter (3.84 ms … 4.69 ms) 4.1 ms 4.55 ms 4.69 ms
@discordjs/opus:
3 168 ops/s, ±0.53% | 24.75% slower
summary for OpusEncoder
opusscript
1.13x faster than mediaplex
1.22x faster than @evan/opus
1.26x faster than @discordjs/opus
1.88x faster than @evan/opus (wasm)
16.06x faster than opusscript (no wasm)
@evan/opus:
3 283 ops/s, ±0.25% | 22.02% slower
@evan/opus (wasm):
2 242 ops/s, ±0.39% | 46.75% slower
cpu: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
runtime: node v20.6.1 (x64-win32)
opusscript:
4 210 ops/s, ±0.20% | fastest
benchmark time (avg) (min … max) p75 p99 p995
------------------------------------------------------------ -----------------------------
• OpusDecoder
------------------------------------------------------------ -----------------------------
mediaplex 92.94 µs/iter (84.8 µs … 1.22 ms) 90.8 µs 143.5 µs 161.8 µs
@discordjs/opus 87.75 µs/iter (81 µs … 376.1 µs) 86.3 µs 130.2 µs 142 µs
@evan/opus 91.22 µs/iter (84.7 µs … 320.2 µs) 89.9 µs 133.4 µs 142 µs
@evan/opus (wasm) 146.92 µs/iter (130.3 µs … 966.5 µs) 137.7 µs 298.7 µs 309.3 µs
opusscript 169.56 µs/iter (159.5 µs … 448.9 µs) 167.2 µs 232.6 µs 258.6 µs
opusscript (no wasm) 482.66 µs/iter (443.7 µs … 1.56 ms) 456.5 µs 965.8 µs 995.3 µs
opusscript (no wasm):
245 ops/s, ±3.69% | slowest, 94.18% slower
Finished 6 cases!
Fastest: opusscript
Slowest: opusscript (no wasm)
Running "OpusDecoder Benchmark" suite...
mediaplex:
10 726 ops/s, ±0.50% | 9.42% slower
@discordjs/opus:
11 841 ops/s, ±0.55% | fastest
@evan/opus:
11 382 ops/s, ±0.46% | 3.88% slower
@evan/opus (wasm):
7 461 ops/s, ±0.32% | 36.99% slower
opusscript:
6 138 ops/s, ±0.38% | 48.16% slower
opusscript (no wasm):
2 252 ops/s, ±0.73% | slowest, 80.98% slower
Finished 6 cases!
Fastest: @discordjs/opus
Slowest: opusscript (no wasm)
summary for OpusDecoder
@discordjs/opus
1.04x faster than @evan/opus
1.06x faster than mediaplex
1.67x faster than @evan/opus (wasm)
1.93x faster than opusscript
5.5x faster than opusscript (no wasm)
```
These benchmarks compare the performance of Mediaplex's Opus encoder/decoder to other popular Opus libraries.
+3 -1
View File
@@ -56,7 +56,9 @@ export const generateOpusSample = () => {
export const createMediaplexEncoder = (config) => new mediaplex.OpusEncoder(config.SAMPLE_RATE, config.CHANNELS);
export const createDjsEncoder = (config) => new djs.OpusEncoder(config.SAMPLE_RATE, config.CHANNELS);
export const createOpusScriptWasmEncoder = (config) => new opusscript(config.SAMPLE_RATE, config.CHANNELS, opusscript.Application.AUDIO);
export const createOpusScriptWasmEncoder = (config) => new opusscript(config.SAMPLE_RATE, config.CHANNELS, opusscript.Application.AUDIO, {
wasm: true
});
export const createOpusScriptAsmEncoder = (config) => new opusscript(config.SAMPLE_RATE, config.CHANNELS, opusscript.Application.AUDIO, {
wasm: false
});
+28 -19
View File
@@ -1,5 +1,15 @@
import b from 'benny';
import { createDjsEncoder, createMediaplexEncoder, createOpusScriptAsmEncoder, createOpusScriptWasmEncoder, generateOpusSample, createEvanOpusDecoder, createEvanOpusDecoderWasm } from './common.mjs';
import * as mitata from 'mitata';
// prettier-ignore
import {
createDjsEncoder,
createMediaplexEncoder,
createOpusScriptAsmEncoder,
createOpusScriptWasmEncoder,
generateOpusSample,
createEvanOpusDecoder,
createEvanOpusDecoderWasm
} from './common.mjs';
const config = {
FRAME_SIZE: 960,
@@ -16,26 +26,25 @@ const evanOpusWasm = createEvanOpusDecoderWasm(config);
const SAMPLE = generateOpusSample();
b.suite(
'OpusDecoder Benchmark',
b.add('mediaplex', () => {
mitata.group('OpusDecoder', () => {
mitata.bench('mediaplex', () => {
mediaplexEncoder.decode(SAMPLE);
}),
b.add('@discordjs/opus', () => {
});
mitata.bench('@discordjs/opus', () => {
nativeEncoder.decode(SAMPLE);
}),
b.add('@evan/opus', () => {
});
mitata.bench('@evan/opus', () => {
evanOpus.decode(SAMPLE);
}),
b.add('@evan/opus (wasm)', () => {
});
mitata.bench('@evan/opus (wasm)', () => {
evanOpusWasm.decode(SAMPLE);
}),
b.add('opusscript', () => {
});
mitata.bench('opusscript', () => {
wasmEncoder.decode(SAMPLE);
}),
b.add('opusscript (no wasm)', () => {
});
mitata.bench('opusscript (no wasm)', () => {
asmEncoder.decode(SAMPLE);
}),
b.cycle(),
b.complete(),
);
});
});
await mitata.run();
+27 -19
View File
@@ -1,5 +1,14 @@
import b from 'benny';
import { createDjsEncoder, createMediaplexEncoder, createOpusScriptAsmEncoder, createOpusScriptWasmEncoder, generatePCMSample, createEvanOpusEncoder, createEvanOpusEncoderWasm } from './common.mjs';
import * as mitata from 'mitata';
// prettier-ignore
import {
createDjsEncoder,
createMediaplexEncoder,
createOpusScriptAsmEncoder,
createOpusScriptWasmEncoder,
generatePCMSample,
createEvanOpusEncoder,
createEvanOpusEncoderWasm
} from './common.mjs';
const config = {
FRAME_SIZE: 960,
@@ -16,26 +25,25 @@ const evanOpusWasm = createEvanOpusEncoderWasm(config);
const SAMPLE = generatePCMSample(config.FRAME_SIZE * config.CHANNELS * 6);
b.suite(
'OpusEncoder Benchmark',
b.add('mediaplex', () => {
mitata.group('OpusEncoder', () => {
mitata.bench('mediaplex', () => {
mediaplexEncoder.encode(SAMPLE);
}),
b.add('@discordjs/opus', () => {
});
mitata.bench('@discordjs/opus', () => {
nativeEncoder.encode(SAMPLE);
}),
b.add('@evan/opus', () => {
});
mitata.bench('@evan/opus', () => {
evanOpus.encode(SAMPLE);
}),
b.add('@evan/opus (wasm)', () => {
});
mitata.bench('@evan/opus (wasm)', () => {
evanOpusWasm.encode(SAMPLE);
}),
b.add('opusscript', () => {
});
mitata.bench('opusscript', () => {
wasmEncoder.encode(SAMPLE, config.FRAME_SIZE);
}),
b.add('opusscript (no wasm)', () => {
});
mitata.bench('opusscript (no wasm)', () => {
asmEncoder.encode(SAMPLE, config.FRAME_SIZE);
}),
b.cycle(),
b.complete(),
);
});
});
await mitata.run();
+13 -66
View File
@@ -1,65 +1,22 @@
include:
- template: 'Workflows/Branch-Pipelines.gitlab-ci.yml'
# https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: $CI_COMMIT_BRANCH
- if: $CI_COMMIT_TAG
default:
tags:
- docker
image: 'debian:bookworm-slim'
# https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html#reference-tags
.snippets:
git_prep:
# Make sure we have a recent annotated tag, otherwise meson/get-version.py
# might fail later (e.g. shallow clone without enough history) or return
# a bogus version based on a much older tag. This can happen in merge request
# pipelines from a personal fork, as the fork might not have the latest
# upstream tags if it has been forked a long time ago. Also affects the
# git version picked up by autotools and cmake, not just meson.
- git fetch https://gitlab.xiph.org/xiph/opus.git refs/tags/v1.4:refs/tags/v1.4
- git describe
# Image from https://hub.docker.com/_/gcc/ based on Debian
image: gcc:9
whitespace:
stage: test
before_script:
- apt-get update &&
apt-get install -y git
script:
- git diff-tree --check origin/master HEAD
# Make sure commits are GPG signed
ci-fairy:
stage: test
script:
- apt update
- apt install -y python3-pip git
- pip3 install --break-system-packages git+https://gitlab.freedesktop.org/freedesktop/ci-templates@7811ba9814a3bad379377241c6c6b62d78b20eac
- echo Checking commits $CI_FAIRY_BASE_COMMIT..HEAD
- ci-fairy check-commits --gpg-signed-commit $CI_FAIRY_BASE_COMMIT..HEAD
tags:
- 'docker'
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
CI_FAIRY_BASE_COMMIT: $CI_MERGE_REQUEST_DIFF_BASE_SHA
- if: $CI_PIPELINE_SOURCE != "merge_request_event"
variables:
CI_FAIRY_BASE_COMMIT: 'HEAD^1'
autoconf:
stage: build
before_script:
- apt-get update &&
apt-get install -y zip doxygen git automake libtool make
- !reference [.snippets, git_prep]
apt-get install -y zip doxygen
script:
- ./autogen.sh
- ./configure
@@ -78,37 +35,27 @@ cmake:
stage: build
before_script:
- apt-get update &&
apt-get install -y cmake ninja-build git
- !reference [.snippets, git_prep]
apt-get install -y cmake ninja-build
script:
- mkdir build
- cmake -S . -B build -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DOPUS_BUILD_TESTING=ON -DOPUS_BUILD_PROGRAMS=ON
- cmake --build build
- cd build && ctest --output-on-failure
.meson:
image: 'debian:bookworm-slim'
meson:
stage: build
before_script:
- apt-get update &&
apt-get install -y ninja-build doxygen meson git
- !reference [.snippets, git_prep]
apt-get install -y python3-pip ninja-build doxygen
- export XDG_CACHE_HOME=$PWD/pip-cache
- pip3 install --user meson
script:
- export PATH=$PATH:$HOME/.local/bin
- mkdir builddir
- meson setup -Dtests=enabled -Ddocs=enabled -Dbuildtype=release builddir ${MESON_EXTRA_ARGS}
- meson setup --werror -Dtests=enabled -Ddocs=enabled -Dbuildtype=release builddir
- meson compile -C builddir
- meson test -C builddir
#- meson dist --no-tests -C builddir
meson x86_64:
extends: '.meson'
variables:
MESON_EXTRA_ARGS: '--werror'
meson arm64:
extends: '.meson'
tags:
- 'gstreamer-arm64-linux-docker'
variables:
# arm64 build has a compiler warning still, so let's not use --werror for now
MESON_EXTRA_ARGS: '-Dwerror=false'
cache:
paths:
- 'pip-cache/*'
+1 -1
View File
@@ -1450,7 +1450,7 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end,
if (encode && resynth)
lowband_scratch = _lowband_scratch;
else
lowband_scratch = X_+M*eBands[m->effEBands-1];
lowband_scratch = X_+M*eBands[m->nbEBands-1];
ALLOC(X_save, resynth_alloc, celt_norm);
ALLOC(Y_save, resynth_alloc, celt_norm);
ALLOC(X_save2, resynth_alloc, celt_norm);
-132
View File
@@ -1,132 +0,0 @@
# Using CMake for the Opus Project
This guide provides instructions for using CMake to build the Opus project with various configuration options. CMake is a widely used build system generator that helps manage the build process across different platforms.
Note: Please keep in mind that software documentation can sometimes go out of date as new versions are released. It is always recommended to refer to the official CMake documentation for the most up-to-date and accurate information. You can find the official CMake documentation at [cmake.org/documentation](https://cmake.org/documentation/).
## Prerequisites
Before proceeding, make sure you have the following prerequisites installed:
- CMake
- Git (optional, but recommended for version control integration)
- Working C compiler
## Build Instructions
Follow the steps below to build the Opus project using CMake:
1. Clone the Opus repository using Git:
```shell
git clone https://gitlab.xiph.org/xiph/opus
```
2. Create a build directory within the Opus repository:
```shell
cd opus
mkdir build
cd build
```
3. Configure the build with CMake. You can set the desired configuration options using CMake's `-D` flag. Here are some available options:
- `OPUS_BUILD_SHARED_LIBRARY`: build shared library.
- `OPUS_BUILD_TESTING`: build tests.
- `OPUS_BUILD_PROGRAMS`: build programs.
- `OPUS_CUSTOM_MODES`, enable non-Opus modes, e.g. 44.1 kHz & 2^n frames.
For example, to enable the custom modes and build programs, use the following command:
```shell
cmake .. -DOPUS_BUILD_PROGRAMS=ON -DOPUS_BUILD_TESTING=ON
```
4. Build the Opus project:
```shell
cmake --build .
```
5. After a successful build, you can find the compiled Opus library and associated files in the build directory.
## Testing with CTest
Opus provides a comprehensive test suite to ensure the functionality and correctness of the project. You can execute the tests using CTest, a part of the CMake build system. CTest allows for automated testing and provides useful features for managing and evaluating the test results.
To run the Opus tests using CTest, follow these steps:
1. Navigate to the build directory after configuring and building the project with CMake:
```shell
cd build
```
2. Execute the tests using CTest:
```shell
ctest
```
Note: For Windows you need to specify which configuration to test
```shell
ctest -C Debug
```
## Platform Support and Bug Reporting
CMake aims to provide broad platform support, allowing the Opus project to be built and used on major operating systems and platforms. The supported platforms include:
- Windows
- macOS
- Linux
- Android
- iOS
CMake achieves platform support by generating platform-specific build files (e.g., Makefiles, Visual Studio projects) based on the target platform. This allows developers to build and configure the Opus project consistently across different operating systems and environments.
While CMake strives to ensure compatibility and stability across platforms, bugs or issues may still arise in specific configurations. If you encounter any problems during the configuration process or while building the Opus project, we encourage you to file an issue in the [project's issue tracker](https://gitlab.xiph.org/xiph/opus/-/issues).
When reporting an issue, please provide the following information to help us understand and reproduce the configuration problem effectively:
1. Detailed description of the issue, including any error messages or unexpected behavior observed.
2. Steps to reproduce the problem, including the CMake command and any specific configuration options used.
3. Operating system and version (e.g., Windows 10, macOS Big Sur, Ubuntu 20.04).
4. CMake version (e.g., CMake 3.21.1).
5. Any relevant information about the platform, toolchain, or dependencies used.
6. Additional context or details that might assist in troubleshooting the issue.
By providing thorough information when reporting configuration issues, you contribute to improving the Opus project's compatibility and reliability across different platforms.
We appreciate your help in identifying and addressing any configuration-related problems, ensuring a better experience for all users of the Opus project.
## Platform Specific Examples
Note: Examples can go out of date. Always refer to documentation for latest reference.
### Cross compiling for Android
```shell
cmake .. -DCMAKE_TOOLCHAIN_FILE=${ANDROID_HOME}/ndk/25.2.9519653/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a
```
For more information about cross compiling for android, you can refer to the [Cross compiling for Android documentation](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android).
### Cross compiling for iOS
```shell
cmake .. -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=arm64
```
For more information about cross compilation for iOS, you can refer to the [Cross compiling for iOS documentation](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-ios-tvos-or-watchos).
### Windows Visual Studio
```shell
cmake .. -G "Visual Studio 17 2022" -A x64
```
For more information about the Visual Studio generator options and additional customization, you can refer to the [Visual Studio Generator documentation](https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2017%202022.html).
+1 -1
View File
@@ -46,5 +46,5 @@ cat ${HTML} | sed -e 's/ *$//g' > ${HTML}+ && mv ${HTML}+ ${HTML}
cat ${CSS} | sed -e 's/ *$//g' > ${CSS}+ && mv ${CSS}+ ${CSS}
VERSION=$(grep -F Version ${HTML} | sed 's/.*Version \([0-9]\.[0-9]\.[0-9]\).*/\1/')
VERSION=$(fgrep Version ${HTML} | sed 's/.*Version \([0-9]\.[0-9]\.[0-9]\).*/\1/')
echo Now at version ${VERSION}
+1 -1
View File
@@ -574,8 +574,8 @@ foreach l : lines
endforeach
subdir('include')
subdir('celt')
subdir('silk')
subdir('celt')
subdir('src')
configure_file(output: 'config.h', configuration: opus_conf)
+1 -1
View File
@@ -24,7 +24,7 @@
"@napi-rs/cli": "^2.16.3",
"@types/node": "^20.6.0",
"ava": "5.3.1",
"benny": "^3.7.1",
"mitata": "^0.1.6",
"opusscript": "^0.1.0"
},
"ava": {
+1 -1
View File
@@ -31,7 +31,7 @@ pub fn get_opus_version() -> String {
let version_cstr = unsafe { core::ffi::CStr::from_ptr(version_string) };
// fallback to commit hash
let version_string = version_cstr.to_str().unwrap_or("101a71e0").to_owned();
let version_string = version_cstr.to_str().unwrap_or("82ac57d").to_owned();
version_string
}
+8
View File
@@ -1518,6 +1518,7 @@ __metadata:
"@types/node": ^20.6.0
ava: 5.3.1
benny: ^3.7.1
mitata: ^0.1.6
opusscript: ^0.1.0
languageName: unknown
linkType: soft
@@ -1665,6 +1666,13 @@ __metadata:
languageName: node
linkType: hard
"mitata@npm:^0.1.6":
version: 0.1.6
resolution: "mitata@npm:0.1.6"
checksum: fe64e22ae17bfb748a0d71b2ecf1f64da09c633520c819ac409018a49843adfd9817612a152651e5f1fa080f227fc382e0cdbb92a11e2f69f3cc9f843ba7d603
languageName: node
linkType: hard
"mkdirp@npm:^1.0.3":
version: 1.0.4
resolution: "mkdirp@npm:1.0.4"