From 51b04ddfe4eb2e1060aaf870a8f60cabd0d3260c Mon Sep 17 00:00:00 2001 From: Greg Bogdan Date: Sun, 2 Feb 2025 15:38:29 +0100 Subject: [PATCH 1/2] Added PowerShell script for windows machines --- README.md | 24 ++++++++++++++- obench.ps1 | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 obench.ps1 diff --git a/README.md b/README.md index caf3bf8..394f795 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![.github/workflows/shellcheck.yaml](https://github.com/geerlingguy/ollama-benchmark/actions/workflows/shellcheck.yaml/badge.svg)](https://github.com/geerlingguy/ollama-benchmark/actions/workflows/shellcheck.yaml) +## Linux + This bash script benchmarks ollama on any system where it is installed. For a quick installation, try: @@ -26,7 +28,7 @@ Then run this benchmark script: Uninstall Ollama following the [official uninstall instructions](https://github.com/ollama/ollama/blob/main/docs/linux.md#uninstall). -## CLI Options +###CLI Options ``` Usage: ./obench.sh [OPTIONS] @@ -39,6 +41,26 @@ Options: --markdown Format output as markdown ``` +## Windows + +This PowerShell script benchmarks ollama on any system where it is installed. + +> Make sure you have Ollama installed on your windows machine + +### CLI Options + +``` +Usage: .\obench.ps1 [OPTIONS] +Options: + -Help Display this help message + -Default Run a benchmark using some default small models + -Model Specify a model to use + -Count Number of times to run the benchmark + -Ollama-bin Point to ollama executable or command (e.g if using Docker) + -Markdown Format output as markdown +``` + + ## Findings ### DeepSeek diff --git a/obench.ps1 b/obench.ps1 new file mode 100644 index 0000000..8da7379 --- /dev/null +++ b/obench.ps1 @@ -0,0 +1,85 @@ +# PowerShell script to benchmark Ollama token generation rate +# Inspired by https://taoofmac.com/space/blog/2024/01/20/1800 + +param ( + [switch]$Help, + [switch]$Default, + [string]$Model, + [int]$Count, + [string]$OllamaBin = "ollama", + [switch]$Markdown +) + +function Show-Usage { + Write-Output "Usage: obench.ps1 [OPTIONS]" + Write-Output "Options:" + Write-Output " -Help Display this help message" + Write-Output " -Default Run a benchmark using some default small models" + Write-Output " -Model Specify a model to use" + Write-Output " -Count Number of times to run the benchmark" + Write-Output " -Ollama-bin Point to ollama executable or command (e.g if using Docker)" + Write-Output " -Markdown Format output as markdown" + exit 0 +} + +# Parse command-line arguments + +if ($Help) { + Show-Usage + exit 0 +} + +# Default values +if ($Default) { + $Count = 3 + $Model = "llama3.2:3b" +} + +# Ensure Ollama is available +$baseCmd = ($OllamaBin -split " ")[0] +if (-not (Get-Command $baseCmd -ErrorAction SilentlyContinue)) { + Write-Error "Error: $baseCmd could not be found. Please check the path or install it." + exit 1 +} + +# Prompt for benchmark count if not provided +if (-not $Count) { + $Count = Read-Host "How many times to run the benchmark?" +} + +# Prompt for model if not provided +if (-not $Model) { + Write-Output "Current models available locally:" + & $OllamaBin list + $Model = Read-Host "Enter model you'd like to run (e.g. llama3.2)" +} + +Write-Output "Running benchmark $Count times using model: $Model" +Write-Output "" +if ($Markdown) { + Write-Output "| Run | Eval Rate (Tokens/Second) |" + Write-Output "|-----|---------------------------|" +} + +$totalEvalRate = 0 +for ($run = 1; $run -le $Count; $run++) { + $result = echo "Why is the blue sky blue?" | & $OllamaBin run $Model --verbose 2>&1 | Select-String "^eval rate:" + + if ($result) { + $evalRate = ($result -split " ")[1] + $tokenValue = ($evalRate -split " ")[0] + $totalEvalRate += [double]$tokenValue + if ($Markdown) { + Write-Output "| $run | $evalRate tokens/s |" + } else { + Write-Output $result + } + } +} + +$averageEvalRate = [math]::Round($totalEvalRate / $Count, 2) +if ($Markdown) { + Write-Output "|**Average Eval Rate**| $averageEvalRate tokens/second |" +} else { + Write-Output "Average Eval Rate: $averageEvalRate tokens/second" +} From 7152227326f9c2bd4b7cbd922f31734502b4dafc Mon Sep 17 00:00:00 2001 From: Greg Bogdan Date: Sun, 2 Feb 2025 15:40:33 +0100 Subject: [PATCH 2/2] removed unnecessary comment --- obench.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/obench.ps1 b/obench.ps1 index 8da7379..1b21dd3 100644 --- a/obench.ps1 +++ b/obench.ps1 @@ -22,8 +22,6 @@ function Show-Usage { exit 0 } -# Parse command-line arguments - if ($Help) { Show-Usage exit 0