Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 6dcc9d5

Browse files
committed
Add SimpleInsertSelectBenchmark
1 parent 4a6cad4 commit 6dcc9d5

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System.Diagnostics;
2+
using NUnit.Framework;
3+
using ServiceStack.DataAnnotations;
4+
using ServiceStack.Text;
5+
6+
namespace ServiceStack.OrmLite.Tests.Issues
7+
{
8+
public class TableWithStrings
9+
{
10+
[AutoIncrement]
11+
public int Id { get; set; }
12+
public string String01 { get; set; }
13+
public string String02 { get; set; }
14+
public string String03 { get; set; }
15+
public string String04 { get; set; }
16+
public string String05 { get; set; }
17+
public string String06 { get; set; }
18+
public string String07 { get; set; }
19+
public string String08 { get; set; }
20+
public string String09 { get; set; }
21+
public string String10 { get; set; }
22+
public string String11 { get; set; }
23+
public string String12 { get; set; }
24+
public string String13 { get; set; }
25+
public string String14 { get; set; }
26+
public string String15 { get; set; }
27+
public string String16 { get; set; }
28+
public string String17 { get; set; }
29+
public string String18 { get; set; }
30+
public string String19 { get; set; }
31+
public string String20 { get; set; }
32+
33+
public static TableWithStrings Create(int i)
34+
{
35+
return new TableWithStrings
36+
{
37+
String01 = "String: " + i,
38+
String02 = "String: " + i,
39+
String03 = "String: " + i,
40+
String04 = "String: " + i,
41+
String05 = "String: " + i,
42+
String06 = "String: " + i,
43+
String07 = "String: " + i,
44+
String08 = "String: " + i,
45+
String09 = "String: " + i,
46+
String10 = "String: " + i,
47+
String11 = "String: " + i,
48+
String12 = "String: " + i,
49+
String13 = "String: " + i,
50+
String14 = "String: " + i,
51+
String15 = "String: " + i,
52+
String16 = "String: " + i,
53+
String17 = "String: " + i,
54+
String18 = "String: " + i,
55+
String19 = "String: " + i,
56+
String20 = "String: " + i,
57+
};
58+
}
59+
}
60+
61+
[NUnit.Framework.Ignore, TestFixture]
62+
[Category("Benchmark")]
63+
public class SimpleInsertSelectBenchmark
64+
{
65+
[Test]
66+
public void Simple_Perf_test_using_InMemory_Sqlite()
67+
{
68+
var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
69+
using (var db = dbFactory.Open())
70+
{
71+
db.DropAndCreateTable<TableWithStrings>();
72+
73+
var sw = Stopwatch.StartNew();
74+
for (int i = 0; i < 100; i++)
75+
{
76+
var row = TableWithStrings.Create(i);
77+
db.Insert(row);
78+
}
79+
"[:memory:] Time to INSERT 100 rows: {0}ms".Print(sw.ElapsedMilliseconds);
80+
81+
sw = Stopwatch.StartNew();
82+
var rows = db.Select<TableWithStrings>();
83+
"[:memory:] Time to SELECT {0} rows: {1}ms".Print(rows.Count, sw.ElapsedMilliseconds);
84+
}
85+
}
86+
87+
[Test]
88+
public void Simple_Perf_test_using_File_Sqlite()
89+
{
90+
var dbPath = "~/App_Data/db.sqlite".MapProjectPath();
91+
var dbFactory = new OrmLiteConnectionFactory(dbPath, SqliteDialect.Provider);
92+
using (var db = dbFactory.Open())
93+
{
94+
db.DropAndCreateTable<TableWithStrings>();
95+
96+
var sw = Stopwatch.StartNew();
97+
for (int i = 0; i < 100; i++)
98+
{
99+
var row = TableWithStrings.Create(i);
100+
db.Insert(row);
101+
}
102+
"[db.sqlite] Time to INSERT 100 rows: {0}ms".Print(sw.ElapsedMilliseconds);
103+
104+
sw = Stopwatch.StartNew();
105+
var rows = db.Select<TableWithStrings>();
106+
"[db.sqlite] Time to SELECT {0} rows: {1}ms".Print(rows.Count, sw.ElapsedMilliseconds);
107+
}
108+
}
109+
}
110+
}

tests/ServiceStack.OrmLite.Tests/ServiceStack.OrmLite.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<Compile Include="Issues\BelongsToIssue.cs" />
132132
<Compile Include="Issues\CanBuildExpressionWithAbstractType.cs" />
133133
<Compile Include="Issues\ColumnGuessingTests.cs" />
134+
<Compile Include="Issues\SimpleInsertSelectBenchmark.cs" />
134135
<Compile Include="Issues\JoinBoolSqlServerIssue.cs" />
135136
<Compile Include="Issues\LoadReferencesFKandSelfRefIssue.cs" />
136137
<Compile Include="Issues\MergingNestedSqlExpressionIssue.cs" />

0 commit comments

Comments
 (0)