Skip to content

Instantly share code, notes, and snippets.

@bgrainger
Created June 8, 2023 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrainger/f0b96e29c99cdf88f8de422879b2631e to your computer and use it in GitHub Desktop.
Save bgrainger/f0b96e29c99cdf88f8de422879b2631e to your computer and use it in GitHub Desktop.
using MySqlConnector;
using System.Diagnostics;
var threadCount = args.Length == 1 && int.TryParse(args[0], out var tc) ? tc : 100;
var csb = new MySqlConnectionStringBuilder
{
Server = // REDACTED
UserID = // REDACTED
Password = // REDACTED
MaximumPoolSize = (uint) threadCount,
ConnectionTimeout = 5,
};
using (var connection = new MySqlConnection(csb.ConnectionString))
{
await connection.OpenAsync();
using var command = connection.CreateCommand();
command.CommandText = "CREATE SCHEMA IF NOT EXISTS test COLLATE utf8mb4_bin";
await command.ExecuteNonQueryAsync();
}
csb.Database = "test";
var tasks = new List<Task>();
for (int i = 0; i < threadCount; i++)
{
tasks.Add(Task.Run(async () =>
{
while (true)
{
using var connection = new MySqlConnection(csb.ConnectionString);
await connection.OpenAsync();
var stopwatch = Stopwatch.StartNew();
using var command = connection.CreateCommand();
command.CommandText = """
DROP TEMPORARY TABLE IF EXISTS test;
CREATE TEMPORARY TABLE test(id INT NOT NULL);
""";
await command.ExecuteNonQueryAsync();
stopwatch.Stop();
Console.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId} - {stopwatch.ElapsedMilliseconds}ms");
}
}));
}
await Task.WhenAll(tasks);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment