Skip to content

Commit

Permalink
Add Dockerfile for benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasmohrin committed Jun 2, 2021
1 parent 767b62d commit 7026b2d
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 0 deletions.
124 changes: 124 additions & 0 deletions benchmarks/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Benchmark Dockerfile for tealdeer
#
# To run the benchmarks, execute
#
# docker build -t tldr-benchmark .
# docker run --privileged --rm -it tldr-benchmark
#
# as root in the directory of this Dockerfile. This will build the compared
# clients and benchmark them with `hyperfine` at the end.
#
# The `--privileged` flag is needed to drop the disk caches before every run. If
# you want to test with hot caches or don't want to use this flag, you will have
# to remove the `--prepare` line from the `hyperfine` command at the end of this
# file and rebuild the image.

################################################################################

FROM rust AS tealdeer-builder

WORKDIR /build
RUN git clone --branch "master" https://github.com/dbrgn/tealdeer.git \
&& cd tealdeer \
&& cargo build --release \
&& mkdir /build-outputs \
&& cp target/release/tldr /build-outputs/tealdeer

################################################################################

FROM ubuntu:latest AS tldr-c-builder

WORKDIR /build
RUN apt-get update && apt-get install -y build-essential git
RUN git clone https://github.com/tldr-pages/tldr-c-client.git \
&& cd tldr-c-client \
&& DEBIAN_FRONTEND=noninteractive ./deps.sh \
&& make \
&& mkdir /build-outputs /deps \
&& cp tldr /build-outputs/tldr-c \
&& cp deps.sh /deps/tldr-c-deps.sh

################################################################################

FROM haskell:8.6 AS haskell-builder

WORKDIR /build

RUN git clone https://github.com/psibi/tldr-hs.git \
&& cd tldr-hs \
&& stack build

RUN git clone https://github.com/gutjuri/fast-tldr \
&& cd fast-tldr \
&& stack build

RUN mkdir /build-outputs \
&& find tldr-hs/.stack-work/dist -type f -iname tldr -exec mv '{}' /build-outputs/tldr-hs \; \
&& find fast-tldr/.stack-work/dist -type f -iname tldr -exec mv '{}' /build-outputs/fast-tldr \;

################################################################################

FROM node:slim AS node-builder

WORKDIR /build-outputs
RUN npm install tldr \
&& cp $(which node) . \
&& echo './node -- ./node_modules/.bin/tldr "$@"' > tldr-node \
&& chmod +x tldr-node

################################################################################


# Currently failing to build
# FROM euantorano/zig:master AS zig-builder

# WORKDIR /build-outputs
# RUN apk add git \
# && git clone https://gitlab.com/ve-nt/outfieldr.git \
# && cd outfieldr \
# && git submodule init \
# && git submodule update \
# && zig build -Drelease-safe

################################################################################

FROM ubuntu:latest AS benchmark

ENV PAGE="tar"
ENV LANG="en_US.UTF-8"

WORKDIR /deps
RUN apt-get update && apt-get install -y wget unzip
COPY --from=tldr-c-builder /deps/* ./
RUN for file in *; do DEBIAN_FRONTEND=noninteractive sh $file; done

WORKDIR /clients
COPY --from=tealdeer-builder /build-outputs/* ./
COPY --from=tldr-c-builder /build-outputs/* ./
COPY --from=haskell-builder /build-outputs/* ./
RUN wget -qO tldr-bash https://4e4.win/tldr && chmod +x tldr-bash
COPY --from=node-builder /build-outputs/node /build-outputs/tldr-node ./
COPY --from=node-builder /build-outputs/node_modules/ ./node_modules/

# Update all the individual caches
# RUN mkdir -p /caches/tealdeer /caches/tldr-c /caches/tldr-hs /caches/fast-tldr /caches/tldr-bash /caches/tldr-node \
RUN bash -c 'mkdir -p /caches/{tealdeer,tldr-c,tldr-hs,fast-tldr,tldr-bash,tldr-node,outfieldr}' \
&& TEALDEER_CACHE_DIR=/caches/tealdeer ./tealdeer -u \
&& TLDR_CACHE_DIR=/caches/tldr-c ./tldr-c -u \
&& XDG_DATA_HOME=/caches/tldr-hs ./tldr-hs -u \
&& XDG_DATA_HOME=/caches/fast-tldr ./fast-tldr -u \
&& XDG_DATA_HOME=/caches/tldr-bash ./tldr-bash -u \
&& HOME=/caches/tldr-node ./tldr-node -u

WORKDIR /tools
RUN wget -q https://github.com/sharkdp/hyperfine/releases/download/v1.11.0/hyperfine_1.11.0_amd64.deb && dpkg -i hyperfine_1.11.0_amd64.deb

WORKDIR /clients
CMD hyperfine --warmup 5 \
--prepare 'sync; echo 3 | tee /proc/sys/vm/drop_caches' \
"TEALDEER_CACHE_DIR=/caches/tealdeer ./tealdeer $PAGE" \
"TLDR_CACHE_DIR=/caches/tldr-c ./tldr-c $PAGE" \
"XDG_DATA_HOME=/caches/tldr-hs ./tldr-hs $PAGE" \
"XDG_DATA_HOME=/caches/fast-tldr ./fast-tldr $PAGE" \
"XDG_DATA_HOME=/caches/tldr-bash TLDR_LESS=0 ./tldr-bash $PAGE" \
"HOME=/caches/tldr-node ./tldr-node $PAGE"
66 changes: 66 additions & 0 deletions benchmarks/old.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
FROM ubuntu:latest

RUN apt update && apt install -y wget git
RUN apt update && apt install -y build-essential
RUN apt update && apt install -y unzip
RUN apt update && apt install -y curl
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash - \
&& apt install -y nodejs

ENV PAGE="tar"

WORKDIR /tools
RUN wget -q https://github.com/sharkdp/hyperfine/releases/download/v1.11.0/hyperfine_1.11.0_amd64.deb && dpkg -i hyperfine_1.11.0_amd64.deb

WORKDIR /clients

RUN wget -qO tealdeer https://github.com/dbrgn/tealdeer/releases/latest/download/tldr-linux-x86_64-musl \
&& chmod +x ./tealdeer \
&& ./tealdeer --update
ENV CLIENTS=tealdeer

RUN git clone https://github.com/tldr-pages/tldr-c-client.git \
&& cd tldr-c-client \
&& DEBIAN_FRONTEND=noninteractive ./deps.sh \
&& make \
&& mv tldr ../tldr-c \
&& cd .. \
&& ./tldr-c --update
ENV CLIENTS=$CLIENTS,tldr-c

# This client errors, don't know what to do with it yet
# RUN wget -qO tldr-bash https://4e4.win/tldr \
# && chmod +x ./tldr-bash \
# && ./tldr-bash --update
# ENV CLIENTS=$CLIENTS,tldr-bash

RUN npm install tldr \
&& ln -s node_modules/.bin/tldr tldr-node \
&& ./tldr-node --update
ENV CLIENTS=$CLIENTS,tldr-node

RUN mkdir go \
&& cd go \
&& wget -qO tldr-go.tar.bz2 https://github.com/k3mist/tldr/raw/master/dist/linux.tar.bz2 \
&& tar xf tldr-go.tar.bz2 \
&& cd .. \
&& mv go/dist/build/linux/tldr tldr-go \
&& ./tldr-go $PAGE
ENV CLIENTS=$CLIENTS,tldr-go

RUN mkdir haskell \
&& cd haskell \
&& wget -qO tldr-hs https://github.com/psibi/tldr-hs/releases/download/v0.9.0/tldr-linux-v0.9.0.tar.gz \
&& tar xf tldr-hs \
&& cd .. \
&& mv haskell/tldr tldr-hs \
&& mkdir -p /root/.local/share/tldr/ \
&& ./tldr-hs --update
ENV CLIENTS=$CLIENTS,tldr-hs

RUN wget -qO fast-tldr https://github.com/gutjuri/fast-tldr/releases/download/1.0/tldr-linux64 \
&& chmod +x fast-tldr \
&& ./fast-tldr --update
ENV CLIENTS=$CLIENTS,fast-tldr

CMD hyperfine --warmup 5 --runs 20 --parameter-list client $CLIENTS "./{client} $PAGE"

0 comments on commit 7026b2d

Please sign in to comment.