Skip to content

Commit

Permalink
Rename and update benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Dec 5, 2024
1 parent 8b7c411 commit 8a3624d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 85 deletions.
57 changes: 57 additions & 0 deletions Source/MQTTnet.Benchmarks/MessageProcessingAspNetCoreBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using MQTTnet.AspNetCore;
using System.Threading.Tasks;

namespace MQTTnet.Benchmarks;

[SimpleJob(RuntimeMoniker.Net80)]
[RPlotExporter]
[RankColumn]
[MemoryDiagnoser]
public class MessageProcessingAspNetCoreBenchmark : BaseBenchmark
{
IMqttClient _mqttClient;
string _payload = string.Empty;

[Params(1 * 1024, 4 * 1024, 8 * 1024)]
public int PayloadSize { get; set; }

[Benchmark]
public async Task Send_1000_Messages_AspNetCore()
{
for (var i = 0; i < 1000; i++)
{
await _mqttClient.PublishStringAsync("A", _payload);
}
}

[GlobalSetup]
public async Task Setup()
{
var builder = WebApplication.CreateBuilder();

builder.Services.AddMqttServer(s => s.WithDefaultEndpoint());
builder.Services.AddMqttClient();
builder.WebHost.UseKestrel(k => k.ListenMqtt());

var app = builder.Build();
await app.StartAsync();

_mqttClient = app.Services.GetRequiredService<IMqttClientFactory>().CreateMqttClient();
var clientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("localhost")
.Build();

await _mqttClient.ConnectAsync(clientOptions);

_payload = string.Empty.PadLeft(PayloadSize, '0');
}
}

This file was deleted.

0 comments on commit 8a3624d

Please sign in to comment.