### Description

Refactors benchmark script.

- One can select which benchmark (pystone, numpy, matplotlib, or `all`) to be run through command-line arguments.
  - We can divide each benchmark to separate CI jobs in the future if needed.
- Move pystone benchmark to benchmark directory, preventing it from being included in Pyodide release.

### Checklists

- [x] Add new / update outdated documentation

Close #2150
MAINT Refactor benchmark script. ### Description

Refactors benchmark script.

- One can select which benchmark (pystone, numpy, matplotlib, or `all`) to be run through command-line arguments.
  - We can divide each benchmark to separate CI jobs in the future if needed.
- Move pystone benchmark to benchmark directory, preventing it from being included in Pyodide release.

### Checklists

- [x] Add new / update outdated documentation

Close #2150
import argparse
import http.server
import os
import pathlib
import socketserver
import sys

BUILD_PATH = pathlib.Path(__file__).resolve().parents[2] / "build"


class Handler(http.server.SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header("Access-Control-Allow-Origin", "*")
        super().end_headers()


Handler.extensions_map[".wasm"] = "application/wasm"


def make_parser(parser):
    parser.description = "Start a server with the supplied " "build_dir and port."
    parser.add_argument(
        "--build_dir",
        action="store",
        type=str,
        default=BUILD_PATH,
        help="set the build directory",
    )
    parser.add_argument(
        "--port", action="store", type=int, default=8000, help="set the PORT number"
    )
    return parser


def server(port):
    httpd = socketserver.TCPServer(("", port), Handler)
    return httpd


def main(args):
    build_dir = args.build_dir
    port = args.port
    httpd = server(port)
    os.chdir(build_dir)
    print(f"serving from {build_dir} at localhost:" + str(port))
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        print("\n...shutting down http server")
        httpd.shutdown()
        sys.exit()


if __name__ == "__main__":
    parser = make_parser(argparse.ArgumentParser())
    args = parser.parse_args()
    main(args)

import argparse
import http.server
import os
import pathlib
import socketserver
import sys

BUILD_PATH = pathlib.Path(__file__).resolve().parents[2] / "build"


class Handler(http.server.SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header("Access-Control-Allow-Origin", "*")
        super().end_headers()


Handler.extensions_map[".wasm"] = "application/wasm"


def make_parser(parser):
    parser.description = "Start a server with the supplied " "build_dir and port."
    parser.add_argument(
        "--build_dir",
        action="store",
        type=str,
        default=BUILD_PATH,
        help="set the build directory",
    )
    parser.add_argument(
        "--port", action="store", type=int, default=8000, help="set the PORT number"
    )
    return parser


def server(port):
    httpd = socketserver.TCPServer(("", port), Handler)
    return httpd


def main(args):
    build_dir = args.build_dir
    port = args.port
    httpd = server(port)
    os.chdir(build_dir)
    print(f"serving from {build_dir} at localhost:" + str(port))
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        print("\n...shutting down http server")
        httpd.shutdown()
        sys.exit()


if __name__ == "__main__":
    parser = make_parser(argparse.ArgumentParser())
    args = parser.parse_args()
    main(args)
