From bb57a2541637df02ff5068d8e0893f7d46c62384 Mon Sep 17 00:00:00 2001 From: Arthur Khachaturov Date: Wed, 4 Sep 2024 23:46:03 +0300 Subject: [PATCH] fix: bloat --- README.md | 2 +- benchmark/requirements.txt | 2 -- benchmark/run.sh | 28 ---------------------------- benchmark/test.go | 6 ------ benchmark/test.js | 7 ------- benchmark/test.py | 7 ------- benchmark/test.sh | 9 --------- src/http_server.sh | 3 +-- src/markdown.sh | 10 ++++++---- 9 files changed, 8 insertions(+), 66 deletions(-) delete mode 100644 benchmark/requirements.txt delete mode 100755 benchmark/run.sh delete mode 100644 benchmark/test.go delete mode 100644 benchmark/test.js delete mode 100644 benchmark/test.py delete mode 100644 benchmark/test.sh diff --git a/README.md b/README.md index 8880837..2cce027 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ http::run "$@" # ⚡ Benchmarks It's... bad 🥲 -All benchmarks were conducted on an i7-1360P laptop with 16GB of RAM using the tool codesenberg/bombardier. The benchmark folder in the repository contains all the source files used for benchmarking, along with a run.sh script to automate the benchmarking process. Here are the detailed results: +All benchmarks were conducted on an i7-1360P laptop with 16GB of RAM using the tool codesenberg/bombardier. Here are the detailed results: ### python3 -m http.server ``` diff --git a/benchmark/requirements.txt b/benchmark/requirements.txt deleted file mode 100644 index e4a286c..0000000 --- a/benchmark/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -flask -gunicorn diff --git a/benchmark/run.sh b/benchmark/run.sh deleted file mode 100755 index 07ec2a0..0000000 --- a/benchmark/run.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -set -e -set -m - -install_gunicorn() { - python3 -m venv .venv - source .venv/bin/activate - pip install gunicorn -} - -declare -a reqs=('node' 'python3' 'go') -declare -A run_cmds=([8082]='go run test.go' [8083]='node test.js' [8084]='gunicorn -w 8 test:app -b localhost:8084' [8000]='python3 -m http.server' [8081]='bash ./test.sh run') - -for package in "${reqs[@]}"; do - command -v "${package}" >/dev/null || { echo "Error! ${package} is not installed on this system."; exit 1; } -done - -command -v bombardier >/dev/null || go install github.com/codesenberg/bombardier@latest -command -v gunicorn >/dev/null || install_gunicorn >/dev/null - -for port in "${!run_cmds[@]}"; do - echo "Running: ${run_cmds[$port]}" - ${run_cmds[$port]} >/dev/null 2>&1 & pid="$!" - sleep 0.5 - bombardier -d 30s http://127.0.0.1:"$port" - kill -TERM -- -"$pid" -done diff --git a/benchmark/test.go b/benchmark/test.go deleted file mode 100644 index 4cee126..0000000 --- a/benchmark/test.go +++ /dev/null @@ -1,6 +0,0 @@ -package main -import ( "net/http") -func main() { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("{}")) }); - http.ListenAndServe(":8082", nil); -} diff --git a/benchmark/test.js b/benchmark/test.js deleted file mode 100644 index a9d5326..0000000 --- a/benchmark/test.js +++ /dev/null @@ -1,7 +0,0 @@ -const http = require('http'); -const server = http.createServer((req, res) => { - res.statusCode = 200; - res.setHeader('Content-Type', 'application/json'); - res.end("{}"); -}); -server.listen(8083); diff --git a/benchmark/test.py b/benchmark/test.py deleted file mode 100644 index b3bc2b8..0000000 --- a/benchmark/test.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask import Flask - -app = Flask('app') - -@app.get("/") -def root(): - return "{}" diff --git a/benchmark/test.sh b/benchmark/test.sh deleted file mode 100644 index 7a85247..0000000 --- a/benchmark/test.sh +++ /dev/null @@ -1,9 +0,0 @@ -. ../src/http_server.sh - -http::bind "127.0.0.1" "8081" - -main() { - http::response 200 -} && http::get main "/" - -http::run "$@" diff --git a/src/http_server.sh b/src/http_server.sh index a7a4fc9..f18a231 100644 --- a/src/http_server.sh +++ b/src/http_server.sh @@ -39,9 +39,8 @@ http::run() { http::host() { export HTTP_HOST_NAME="$1"; } http::bind() { export HTTP_HOST="${1:-${HTTP_DEFAULT_HOST}}"; export HTTP_PORT="${2:-${HTTP_DEFAULT_PORT}}"; } -http::markdown_base() { export HTTP_MARKDOWN_BASE="$1"; } -http::static_folder() { +http::static_folder() { # TODO add multiple static folders http__handlers["GET,$1/**"]="http::_static_file" http__all_routes["$1/**"]=1 export HTTP_STATIC_FOLDER="$2"; diff --git a/src/markdown.sh b/src/markdown.sh index fc2eec0..d8a7c7a 100644 --- a/src/markdown.sh +++ b/src/markdown.sh @@ -5,14 +5,16 @@ export HTTP_GUARD__MARKDOWN_SH='' http::_convert_to_md() { - local -a pandoc_options=( - '--from=gfm+tex_math_dollars ' - '--to=html' + local -a _pandoc_options=( + '--from=gfm+tex_math_dollars+footnotes+emoji-autolink_bare_uris' + '--to=html+raw_html' '--mathjax' '--toc' "--template=${HTTP_MARKDOWN_BASE:-'default.html5'}" + "--variable=published_time=$(date -Iseconds -d"$(stat "$1" | grep 'Birth:' | sed 's/.*Birth:\s//')")" + "${pandoc_options[@]}" ) - pandoc "${pandoc_options[@]}" "$1" + pandoc "${_pandoc_options[@]}" "$1" } http::md() {