{"id":28690962,"url":"https://github.com/dirkjbosman/ml-inference-benchmarks","last_synced_at":"2026-04-09T16:16:00.252Z","repository":{"id":298191534,"uuid":"999037947","full_name":"dirkjbosman/ml-inference-benchmarks","owner":"dirkjbosman","description":"Compare inference performance of ML models across C++ vs Python","archived":false,"fork":false,"pushed_at":"2025-06-09T21:27:25.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-09T22:27:28.521Z","etag":null,"topics":["cpp","inference","inference-engine","ml","mlops","modelserving","onnx","onnxruntime","python"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dirkjbosman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-09T16:35:27.000Z","updated_at":"2025-06-09T21:27:28.000Z","dependencies_parsed_at":"2025-06-09T22:37:44.307Z","dependency_job_id":null,"html_url":"https://github.com/dirkjbosman/ml-inference-benchmarks","commit_stats":null,"previous_names":["dirkjbosman/ml-inference-benchmarks"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dirkjbosman/ml-inference-benchmarks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkjbosman%2Fml-inference-benchmarks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkjbosman%2Fml-inference-benchmarks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkjbosman%2Fml-inference-benchmarks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkjbosman%2Fml-inference-benchmarks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dirkjbosman","download_url":"https://codeload.github.com/dirkjbosman/ml-inference-benchmarks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkjbosman%2Fml-inference-benchmarks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259773848,"owners_count":22909159,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","inference","inference-engine","ml","mlops","modelserving","onnx","onnxruntime","python"],"created_at":"2025-06-14T06:30:34.523Z","updated_at":"2026-04-09T16:15:59.979Z","avatar_url":"https://github.com/dirkjbosman.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ml-inference-benchmarks\n\n## Overview:\n\nThis project compares the inference performance of a simple machine learning model across multiple languages, with a focus on Python and C++. Using the same ONNX-serialized model, we can evaluate how fast each language can run predictions over 1000 iterations.\n\nThe pipeline includes:\n- ✅ A mock churn prediction model (RandomForest) trained in Python\n- 📦 Exported to ONNX format (https://github.com/microsoft/onnxruntime) for cross-platform compatibility\n- 🐍 Python-based inference using onnxruntime\n- 💻 C++-based inference using the ONNX Runtime C++ API\n- 🐳 Docker-based benchmarking setup for reproducibility\n\nThis repo is ideal for developers interested in:\n- Profiling ML inference latency\n- Understanding ONNX Runtime usage across languages\n- Comparing Python vs. C++ performance in real-world deployment\n- Use it as a base to expand your own tests on\n\n## Steps\n\n### Step 1: Train Your Model\n\n```sh\ndocker build -t train-model -f train/Dockerfile .\ndocker run --rm -v $(pwd)/model:/app/model train-model\n```\n\n### Step 2: Build \u0026 Run Benchmark Container To Determine Speed of Inference\n\n#### (a) Python\n```sh\ndocker build -t bench-python -f benchmark/python/Dockerfile .\ndocker run --rm bench-python\n```\n\n#### (b) C++\n```sh\ndocker build -t bench-cpp  -f benchmark/cpp/Dockerfile .\ndocker run --rm bench-cpp\n```\n\n### Step 3: View Inference Benchmark Results (1000 iterations)\n\nKey Takeaways From My Tests:\n* C++ outperformed Python by ~32% in this setup (as expected).\n* Both use ONNX Runtime under the hood, but C++ avoids Python’s interpreter overhead.\n* The performance gap is modest for small models, but could widen with larger models or heavier preprocessing.\n* While Python wins in developer speed and ease of use, C++ (or Rust/Go) might be worth exploring if you’re chasing ultra-low latency on edge or CPU-bound systems. \n* It was interesting to see that Rust or Go is not so well supported in ONNX. Potential gap for development or better support in the future.\n\n| Language | Total Time (ms) | Avg Time/Inference (ms) |\n|----------|------------------|------------------------|\n| Python   | 43               | 0.04                   |\n| C++      | 32.461           | 0.032461               |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkjbosman%2Fml-inference-benchmarks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirkjbosman%2Fml-inference-benchmarks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkjbosman%2Fml-inference-benchmarks/lists"}