forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyImport.cs
More file actions
43 lines (37 loc) · 1.28 KB
/
CopyImport.cs
File metadata and controls
43 lines (37 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using BenchmarkDotNet.Attributes;
using NpgsqlTypes;
namespace Npgsql.Benchmarks
{
public class CopyImport
{
NpgsqlConnection _conn = default!;
NpgsqlCommand _truncateCmd = default!;
const int Rows = 1000;
[GlobalSetup]
public void Setup()
{
_conn = BenchmarkEnvironment.OpenConnection();
using (var cmd = new NpgsqlCommand("CREATE TEMP TABLE data (i1 INT, i2 INT, i3 INT, i4 INT, i5 INT, i6 INT, i7 INT, i8 INT, i9 INT, i10 INT)", _conn))
cmd.ExecuteNonQuery();
_truncateCmd = new NpgsqlCommand("TRUNCATE data", _conn);
_truncateCmd.Prepare();
}
[GlobalCleanup]
public void Cleanup() => _conn.Dispose();
[IterationCleanup]
public void IterationCleanup() => _truncateCmd.ExecuteNonQuery();
[Benchmark]
public void Import()
{
using (var importer = _conn.BeginBinaryImport("COPY data FROM STDIN (FORMAT BINARY)"))
{
for (var row = 0; row < Rows; row++)
{
importer.StartRow();
for (var col = 0; col < 10; col++)
importer.Write(col, NpgsqlDbType.Integer);
}
}
}
}
}