Tests: run benchmarks in container via Docker

This commit is contained in:
Lovell Fuller 2022-09-01 14:58:39 +01:00
parent 0e3bd46ca3
commit 953a94885b
4 changed files with 44 additions and 22 deletions

View File

@ -46,27 +46,10 @@ The I/O limits of the relevant (de)compression library will generally determine
## Running the benchmark test ## Running the benchmark test
Requires _ImageMagick_, _GraphicsMagick_ and _Mapnik_: Requires Docker.
```sh
brew install imagemagick
brew install graphicsmagick
brew install mapnik
```
```sh
sudo apt-get install build-essential imagemagick libmagick++-dev graphicsmagick libmapnik-dev
```
```sh
sudo yum install ImageMagick-devel ImageMagick-c++-devel GraphicsMagick mapnik-devel
```
```sh ```sh
git clone https://github.com/lovell/sharp.git git clone https://github.com/lovell/sharp.git
cd sharp cd sharp/test/bench
npm install --build-from-source ./run-with-docker.sh
cd test/bench
npm install
npm test
``` ```

26
test/bench/Dockerfile Normal file
View File

@ -0,0 +1,26 @@
FROM ubuntu:22.04
ARG BRANCH=main
# Install basic dependencies
RUN apt-get -y update && apt-get install -y build-essential curl git
# Install latest Node.js LTS
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get install -y nodejs
# Install benchmark dependencies
RUN apt-get install -y imagemagick libmagick++-dev graphicsmagick libmapnik-dev
# Install sharp
RUN mkdir /tmp/sharp
RUN cd /tmp && git clone --single-branch --branch $BRANCH https://github.com/lovell/sharp.git
RUN cd /tmp/sharp && npm install --build-from-source
# Install benchmark test
RUN cd /tmp/sharp/test/bench && npm install
RUN cat /etc/os-release | grep VERSION=
RUN node -v
WORKDIR /tmp/sharp/test/bench
CMD [ "node", "perf" ]

View File

@ -10,13 +10,13 @@
"devDependencies": { "devDependencies": {
"@squoosh/cli": "0.7.2", "@squoosh/cli": "0.7.2",
"@squoosh/lib": "0.4.0", "@squoosh/lib": "0.4.0",
"async": "3.2.3", "async": "3.2.4",
"benchmark": "2.1.4", "benchmark": "2.1.4",
"gm": "1.23.1", "gm": "1.23.1",
"imagemagick": "0.1.3", "imagemagick": "0.1.3",
"jimp": "0.16.1", "jimp": "0.16.1",
"mapnik": "4.5.9", "mapnik": "4.5.9",
"semver": "7.3.5" "semver": "7.3.7"
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"engines": { "engines": {

13
test/bench/run-with-docker.sh Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
if ! type docker >/dev/null; then
echo "Please install docker"
exit 1
fi
BRANCH=$(git branch --show-current)
echo "Running sharp performance tests using $BRANCH branch"
docker build --build-arg "BRANCH=$BRANCH" -t sharp-test-bench .
docker run --rm -it sharp-test-bench