This repository was archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 613
Expand file tree
/
Copy pathProgram.cs
More file actions
126 lines (108 loc) · 3.2 KB
/
Program.cs
File metadata and controls
126 lines (108 loc) · 3.2 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Data.Metadata.Edm;
using System.Reflection;
using System.Data.EntityClient;
using System.Data.Linq;
using ServiceStack.DataAnnotations;
namespace SqlMapper
{
class Post
{
public int Id { get; set; }
public string Text { get; set; }
public DateTime CreationDate { get; set; }
public DateTime LastChangeDate { get; set; }
public int? Counter1 { get; set; }
public int? Counter2 { get; set; }
public int? Counter3 { get; set; }
public int? Counter4 { get; set; }
public int? Counter5 { get; set; }
public int? Counter6 { get; set; }
public int? Counter7 { get; set; }
public int? Counter8 { get; set; }
public int? Counter9 { get; set; }
}
class Program
{
public static readonly string connectionString = "Data Source=IO\\SQLEXPRESS;Initial Catalog=tempdb;Integrated Security=True";
//public static readonly string connectionString = "Data Source=.;Initial Catalog=tempdb;Integrated Security=True";
public static SqlConnection GetOpenConnection()
{
var connection = new SqlConnection(connectionString);
connection.Open();
return connection;
}
static void RunPerformanceTests()
{
var test = new PerformanceTests();
Console.WriteLine("Running 500 itrations that load up a post entity");
test.Run(500);
}
static void Main(string[] args)
{
#if DEBUG
RunTests();
#else
EnsureDBSetup();
RunPerformanceTests();
#endif
Console.ReadKey();
}
private static void EnsureDBSetup()
{
using (var cnn = GetOpenConnection())
{
var cmd = cnn.CreateCommand();
cmd.CommandText = @"
if (OBJECT_ID('Posts') is null)
begin
create table Posts
(
Id int identity primary key,
[Text] varchar(max) not null,
CreationDate datetime not null,
LastChangeDate datetime not null,
Counter1 int,
Counter2 int,
Counter3 int,
Counter4 int,
Counter5 int,
Counter6 int,
Counter7 int,
Counter8 int,
Counter9 int
)
set nocount on
declare @i int
declare @c int
declare @id int
set @i = 0
while @i < 5000
begin
insert Posts ([Text],CreationDate, LastChangeDate) values (replicate('x', 2000), GETDATE(), GETDATE())
set @id = @@IDENTITY
set @i = @i + 1
end
end
";
cmd.Connection = cnn;
cmd.ExecuteNonQuery();
}
}
private static void RunTests()
{
var tester = new Tests();
foreach (var method in typeof(Tests).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{
Console.Write("Running " + method.Name);
method.Invoke(tester, null);
Console.WriteLine(" - OK!");
}
}
}
}