Created
November 22, 2025 13:52
-
-
Save gitcrtn/53fbe7cc29171c29f1a4acf49a1dbc1a to your computer and use it in GitHub Desktop.
Token Speed Test for llama-server with port 10000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| using System.Data; | |
| using System.Drawing; | |
| using System.IO; | |
| using System.Linq; | |
| using System.Net; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Windows.Forms; | |
| namespace LlamaCheck | |
| { | |
| public partial class Form1 : Form | |
| { | |
| private TextBox txtLoops; | |
| private TextBox txtNPredict; | |
| private Button btnMeasure; | |
| private TextBox txtResult; | |
| private TextBox txtPrompt; | |
| private Label lblLoops; | |
| private Label lblNPredict; | |
| private Label lblPrompt; | |
| public Form1() | |
| { | |
| InitializeComponent(); | |
| Setup(); | |
| } | |
| private async void btnMeasure_Click(object sender, EventArgs e) | |
| { | |
| int loops = int.Parse(txtLoops.Text); | |
| int nPredict = int.Parse(txtNPredict.Text); | |
| string prompt = txtPrompt.Text; | |
| double totalTps = 0.0; | |
| btnMeasure.Enabled = false; | |
| txtResult.Text = "計測中...\r\n"; | |
| for (int i = 0; i < loops; i++) | |
| { | |
| double tps = await MeasureOnce(prompt, nPredict); | |
| totalTps += tps; | |
| txtResult.AppendText($"試行 {i + 1}: {tps} tokens/s\r\n"); | |
| } | |
| double avg = totalTps / loops; | |
| txtResult.AppendText($"\r\n平均: {avg} tokens/s\r\n"); | |
| btnMeasure.Enabled = true; | |
| } | |
| private async Task<double> MeasureOnce(string prompt, int nPredict) | |
| { | |
| string url = "http://localhost:10000/v1/completions"; | |
| string json = $"{{\"prompt\":\"{prompt}\",\"n_predict\":{nPredict}}}"; | |
| byte[] jsonBytes = Encoding.UTF8.GetBytes(json); | |
| var req = (HttpWebRequest)WebRequest.Create(url); | |
| req.Method = "POST"; | |
| req.ContentType = "application/json"; | |
| req.ContentLength = jsonBytes.Length; | |
| DateTime start = DateTime.Now; | |
| using (var reqStream = await req.GetRequestStreamAsync()) | |
| await reqStream.WriteAsync(jsonBytes, 0, jsonBytes.Length); | |
| string responseText; | |
| using (var res = (HttpWebResponse)await req.GetResponseAsync()) | |
| using (var reader = new StreamReader(res.GetResponseStream())) | |
| responseText = await reader.ReadToEndAsync(); | |
| DateTime end = DateTime.Now; | |
| double sec = (end - start).TotalSeconds; | |
| double tps = Math.Round(nPredict / sec, 2); | |
| return tps; | |
| } | |
| private void Setup() | |
| { | |
| this.txtLoops = new TextBox(); | |
| this.txtNPredict = new TextBox(); | |
| this.txtPrompt = new TextBox(); | |
| this.btnMeasure = new Button(); | |
| this.txtResult = new TextBox(); | |
| this.lblLoops = new Label(); | |
| this.lblNPredict = new Label(); | |
| this.lblPrompt = new Label(); | |
| this.lblLoops.AutoSize = true; | |
| this.lblLoops.Location = new System.Drawing.Point(12, 15); | |
| this.lblLoops.Text = "試行回数:"; | |
| this.txtLoops.Location = new System.Drawing.Point(80, 12); | |
| this.txtLoops.Size = new System.Drawing.Size(80, 22); | |
| this.txtLoops.Text = "5"; | |
| this.lblNPredict.AutoSize = true; | |
| this.lblNPredict.Location = new System.Drawing.Point(12, 45); | |
| this.lblNPredict.Text = "n_predict:"; | |
| this.txtNPredict.Location = new System.Drawing.Point(80, 42); | |
| this.txtNPredict.Size = new System.Drawing.Size(80, 22); | |
| this.txtNPredict.Text = "1500"; | |
| lblPrompt.AutoSize = true; | |
| lblPrompt.Location = new Point(12, 75); | |
| lblPrompt.Text = "Prompt:"; | |
| txtPrompt.Location = new Point(80, 72); | |
| txtPrompt.Size = new System.Drawing.Size(380, 22); | |
| txtPrompt.Text = "test"; | |
| this.btnMeasure.Location = new System.Drawing.Point(180, 12); | |
| this.btnMeasure.Size = new System.Drawing.Size(120, 52); | |
| this.btnMeasure.Text = "計測開始"; | |
| this.btnMeasure.Click += new EventHandler(this.btnMeasure_Click); | |
| this.txtResult.Location = new System.Drawing.Point(12, 110); | |
| this.txtResult.Size = new System.Drawing.Size(460, 270); | |
| this.txtResult.Multiline = true; | |
| this.txtResult.ScrollBars = ScrollBars.Vertical; | |
| // | |
| // Form1 | |
| // | |
| this.ClientSize = new System.Drawing.Size(484, 401); | |
| this.Controls.Add(this.lblLoops); | |
| this.Controls.Add(this.txtLoops); | |
| this.Controls.Add(this.lblNPredict); | |
| this.Controls.Add(this.txtNPredict); | |
| this.Controls.Add(lblPrompt); | |
| this.Controls.Add(txtPrompt); | |
| this.Controls.Add(this.btnMeasure); | |
| this.Controls.Add(this.txtResult); | |
| this.Text = "Llama Speed Test"; | |
| CenterToScreen(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment