|
public class Batch |
|
{ |
|
MySqlConnection[] connection; |
|
MySqlCommand[] preparedCommand; |
|
MySqlCommand[] preparedCommands; |
|
MySqlBatch[] preparedBatchCommand; |
|
MySqlBatch[] preparedBatchCommands; |
|
|
|
[Params(3380, 3104)] |
|
public int Port { get; set; } |
|
|
|
public Batch() |
|
{ |
|
connection = new MySqlConnection[2]; |
|
preparedCommand = new MySqlCommand[2]; |
|
preparedCommands = new MySqlCommand[2]; |
|
preparedBatchCommand = new MySqlBatch[2]; |
|
preparedBatchCommands = new MySqlBatch[2]; |
|
} |
|
|
|
[GlobalSetup] |
|
public void GlobalSetup() |
|
{ |
|
for (var i = 0; i < 2; i++) |
|
{ |
|
var csb = new MySqlConnectionStringBuilder |
|
{ |
|
Server = "127.0.0.1", |
|
Port = (i == 0 ? 3104u : 3380u), |
|
UserID = "root", |
|
Password = "test", |
|
// Database = "test", |
|
SslMode = MySqlSslMode.None, |
|
IgnorePrepare = false, |
|
AllowPublicKeyRetrieval = true, |
|
}; |
|
connection[i] = new MySqlConnection(csb.ConnectionString); |
|
connection[i].Open(); |
|
preparedCommand[i] = new MySqlCommand("SELECT 3;", connection[i]); |
|
preparedCommand[i].Prepare(); |
|
preparedCommands[i] = new MySqlCommand("SELECT 1; SELECT 2;", connection[i]); |
|
preparedCommands[i].Prepare(); |
|
preparedBatchCommand[i] = new MySqlBatch(connection[i]) |
|
{ |
|
BatchCommands = |
|
{ |
|
new MySqlBatchCommand("SELECT 1; SELECT 2;"), |
|
}, |
|
}; |
|
preparedBatchCommand[i].Prepare(); |
|
preparedBatchCommands[i] = new MySqlBatch(connection[i]) |
|
{ |
|
BatchCommands = |
|
{ |
|
new MySqlBatchCommand("SELECT 1;"), |
|
new MySqlBatchCommand("SELECT 2;"), |
|
}, |
|
}; |
|
preparedBatchCommands[i].Prepare(); |
|
} |
|
} |
|
|
|
[Benchmark] |
|
public void Command() |
|
{ |
|
var total = 0; |
|
using (var command = new MySqlCommand("SELECT 1; SELECT 2;", connection[Port == 3104 ? 0 : 1])) |
|
{ |
|
using (var reader = command.ExecuteReader()) |
|
{ |
|
do |
|
{ |
|
while (reader.Read()) |
|
{ |
|
total += reader.GetInt32(0); |
|
} |
|
} while (reader.NextResult()); |
|
} |
|
} |
|
if (total != 3) |
|
throw new InvalidOperationException(); |
|
} |
|
|
|
[Benchmark] |
|
public void Commands() |
|
{ |
|
var total = 0; |
|
using (var command = new MySqlCommand("SELECT 1;", connection[Port == 3104 ? 0 : 1])) |
|
using (var reader = command.ExecuteReader()) |
|
{ |
|
do |
|
{ |
|
while (reader.Read()) |
|
{ |
|
total += reader.GetInt32(0); |
|
} |
|
} while (reader.NextResult()); |
|
} |
|
using (var command = new MySqlCommand("SELECT 2;", connection[Port == 3104 ? 0 : 1])) |
|
using (var reader = command.ExecuteReader()) |
|
{ |
|
do |
|
{ |
|
while (reader.Read()) |
|
{ |
|
total += reader.GetInt32(0); |
|
} |
|
} while (reader.NextResult()); |
|
} |
|
if (total != 3) |
|
throw new InvalidOperationException(); |
|
} |
|
|
|
[Benchmark] |
|
public void PreparedCommand() |
|
{ |
|
var total = 0; |
|
using (var reader = preparedCommand[Port == 3104 ? 0 : 1].ExecuteReader()) |
|
{ |
|
do |
|
{ |
|
while (reader.Read()) |
|
{ |
|
total += reader.GetInt32(0); |
|
} |
|
} while (reader.NextResult()); |
|
} |
|
if (total != 3) |
|
throw new InvalidOperationException(); |
|
} |
|
|
|
[Benchmark] |
|
public void PreparedCommands() |
|
{ |
|
var total = 0; |
|
using (var reader = preparedCommands[Port == 3104 ? 0 : 1].ExecuteReader()) |
|
{ |
|
do |
|
{ |
|
while (reader.Read()) |
|
{ |
|
total += reader.GetInt32(0); |
|
} |
|
} while (reader.NextResult()); |
|
} |
|
if (total != 3) |
|
throw new InvalidOperationException(); |
|
} |
|
|
|
[Benchmark] |
|
public void BatchCommand() |
|
{ |
|
var total = 0; |
|
using (var batch = new MySqlBatch(connection[Port == 3104 ? 0 : 1]) |
|
{ |
|
BatchCommands = |
|
{ |
|
new MySqlBatchCommand("SELECT 1; SELECT 2;"), |
|
}, |
|
}) |
|
{ |
|
using (var reader = batch.ExecuteReader()) |
|
{ |
|
do |
|
{ |
|
while (reader.Read()) |
|
{ |
|
total += reader.GetInt32(0); |
|
} |
|
} while (reader.NextResult()); |
|
} |
|
} |
|
if (total != 3) |
|
throw new InvalidOperationException(); |
|
} |
|
|
|
[Benchmark] |
|
public void BatchCommands() |
|
{ |
|
int total = 0; |
|
using (var batch = new MySqlBatch(connection[Port == 3104 ? 0 : 1]) |
|
{ |
|
BatchCommands = |
|
{ |
|
new MySqlBatchCommand("SELECT 1;"), |
|
new MySqlBatchCommand("SELECT 2;"), |
|
}, |
|
}) |
|
{ |
|
using (var reader = batch.ExecuteReader()) |
|
{ |
|
do |
|
{ |
|
while (reader.Read()) |
|
{ |
|
total += reader.GetInt32(0); |
|
} |
|
} while (reader.NextResult()); |
|
} |
|
} |
|
if (total != 3) |
|
throw new InvalidOperationException(); |
|
} |
|
|
|
[Benchmark] |
|
public void PreparedBatchCommand() |
|
{ |
|
var total = 0; |
|
using (var reader = preparedBatchCommand[Port == 3104 ? 0 : 1].ExecuteReader()) |
|
{ |
|
do |
|
{ |
|
while (reader.Read()) |
|
{ |
|
total += reader.GetInt32(0); |
|
} |
|
} while (reader.NextResult()); |
|
} |
|
if (total != 3) |
|
throw new InvalidOperationException(); |
|
} |
|
|
|
[Benchmark] |
|
public void PreparedBatchCommands() |
|
{ |
|
var total = 0; |
|
using (var reader = preparedBatchCommands[Port == 3104 ? 0 : 1].ExecuteReader()) |
|
{ |
|
do |
|
{ |
|
while (reader.Read()) |
|
{ |
|
total += reader.GetInt32(0); |
|
} |
|
} while (reader.NextResult()); |
|
} |
|
if (total != 3) |
|
throw new InvalidOperationException(); |
|
} |
|
} |