Skip to content

Commit d0ec6ea

Browse files
SQL Bench Code Review and Changes
Removed form mode. The tool is just a console app as of this build.
1 parent 5f607fb commit d0ec6ea

File tree

18 files changed

+102
-1817
lines changed

18 files changed

+102
-1817
lines changed
556 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

SQLBench/CommandLineParser.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace SQLBench
1414
// string result = Parse(args) - once, result contains error message or "" if okay
1515
// ArrayList List = GetArgs(argname) - once per arg, returns an ArrayList of 0..n CommandlineArgs
1616
//
17-
// Arguments can have the following prioperties:
17+
// Arguments can have the following properties:
1818
//
1919
// Case sensitive or case-insensitive
2020
// Required or optional
@@ -26,12 +26,16 @@ namespace SQLBench
2626
//
2727
// appname.exe filename [-out filename] [-g value] [-G] -h value [-flags value [-flags value [...]]]
2828
//
29-
// cp.AddRule(new ArgRule("", true, false, true, true)); // file name is required
30-
// cp.AddRule(new ArgRule("flags", true, true, true, false)); // flags is optional but may appear more than once
31-
// cp.AddRule(new ArgRule("out", true, false, true, false)); // out is optional but may only appear once
32-
// cp.AddRule(new ArgRule("g", true, false, false, false)); // g is optional and case-sensitive
33-
// cp.AddRule(new ArgRule("G", false, false, false, false)); // G is optional and takes no value and is case sensitive
34-
// cp.AddRule(new ArgRule("h", true, false, true, true)); // h is required and takes an argument
29+
// ArgRule(string argName, bool hasValue, bool allowDuplicates = false, bool caseInsensitive = true, bool required = true)
30+
//
31+
// ignore
32+
// name value dup case req
33+
// cp.AddRule(new ArgRule("", true, false, true, true)); // file name is required
34+
// cp.AddRule(new ArgRule("flags", true, true, true, false)); // flags is optional but may appear more than once
35+
// cp.AddRule(new ArgRule("out", true, false, true, false)); // out is optional but may only appear once
36+
// cp.AddRule(new ArgRule("g", true, false, false, false)); // g is optional and case-sensitive
37+
// cp.AddRule(new ArgRule("G", false, false, false, false)); // G is optional and takes no value and is case sensitive
38+
// cp.AddRule(new ArgRule("h", true, false, true, true)); // h is required and takes an argument
3539
//
3640
// argements can appear in any order, as long as name/value pairs are adjacent
3741
// arguments other than -g and -G are case-insensitive

SQLBench/DBTests.cs

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33
using System;
4-
using System.Collections.Generic;
5-
using System.IO;
64
using System.Data.SqlClient;
75
using System.Data;
86
using System.Diagnostics;
@@ -16,48 +14,16 @@ namespace SQLBench
1614
//
1715
class DBTests
1816
{
17+
const int OPEN_COUNT = 1000;
18+
const int LOOP_COUNT = 1000;
1919
public string connstr = "";
2020
public DBTests(string connStr)
2121
{
2222
connstr = connStr;
23-
//if (Source == "File")//this is command line
24-
//{
25-
// if (myFile != "")
26-
// {
27-
// if (File.Exists(myFile))
28-
// {
29-
// Console.WriteLine(myFile);
30-
// ReadFile(myFile);
31-
// }
32-
// else
33-
// {
34-
// connstr.Add(myFile);
35-
// }
36-
// }
37-
// else
38-
// {
39-
// connstr.Add("server=(local);database=Tempdb;Integrated Security=SSPI");
40-
// }
41-
//}
42-
//if (Source == "TextBox")//this comes from the GUI interface
43-
//{
44-
// string[] strArray = myFile.Split('\r');
45-
// foreach(string a in strArray)
46-
// {
47-
// connstr.Add(a);
48-
// }
49-
//}
23+
if (connstr.ToLower().Contains("pooling") == false) connstr += ";Pooling=false";
5024
}
51-
//private void ReadFile(string myFile)
52-
//{
53-
// //Stream lines from the file to the list
54-
// string line;
55-
// StreamReader SR = new StreamReader(myFile);
56-
// while((line = SR.ReadLine()) != null)
57-
// {
58-
// connstr.Add(line);
59-
// }
60-
//}
25+
26+
6127
public void Test()
6228
{
6329
//command line.
@@ -73,7 +39,7 @@ public void ConnTest(out double opentotal, out double closetotal)
7339
SqlConnection connection = new SqlConnection(connstr);
7440
opentotal = 0.0;
7541
closetotal = 0.0;
76-
for (int a = 0; a < 1000; a++)
42+
for (int a = 0; a < OPEN_COUNT; a++)
7743
{
7844
// start timers
7945
//OPen connection
@@ -86,9 +52,9 @@ public void ConnTest(out double opentotal, out double closetotal)
8652
connection.Close();
8753
closeconn.Stop();
8854
}
89-
//calculate ops er second
90-
opentotal = 4000.0 / openconn.Elapsed.TotalMilliseconds*1000;
91-
closetotal = 4000.0 /closeconn.Elapsed.TotalMilliseconds*1000;
55+
//calculate ops per second
56+
opentotal = OPEN_COUNT * 1000.0 / openconn.Elapsed.TotalMilliseconds;
57+
closetotal = OPEN_COUNT * 1000.0 / closeconn.Elapsed.TotalMilliseconds;
9258

9359
}
9460
public void InsertRow(out double myInsert)
@@ -122,7 +88,7 @@ public void InsertRow(out double myInsert)
12288
sqlCommand.ExecuteNonQuery(); //execute query
12389
connection.Close(); // close connection
12490

125-
for (int a = 0; a < 1000; a++)
91+
for (int a = 0; a < LOOP_COUNT; a++)
12692
{
12793
//insert concat string
12894
connection.Open(); //open connection
@@ -132,7 +98,7 @@ public void InsertRow(out double myInsert)
13298
myInsertwatch.Stop(); //stop time
13399
connection.Close(); // close connection
134100
}
135-
myInsert = 1000.0 / myInsertwatch.Elapsed.TotalMilliseconds* 1000; // Caclulate ops er second
101+
myInsert = LOOP_COUNT * 1000.0 / myInsertwatch.Elapsed.TotalMilliseconds; // Caclulate ops per second
136102
}
137103
public void ReadRowsTest(out double TotalReadRec)
138104
{
@@ -144,7 +110,7 @@ public void ReadRowsTest(out double TotalReadRec)
144110
//creat stopwatches
145111
Stopwatch ReadRecord = new Stopwatch();
146112
SqlCommand sqlCommand;//create sqlcommand
147-
for(int a = 0;a<1000;a++)
113+
for(int a = 0; a < LOOP_COUNT; a++)
148114
{
149115
connection.Open(); //open connectoin
150116
sqlCommand = new SqlCommand("SELECT ID,Description FROM P1", connection); //create query
@@ -159,7 +125,7 @@ public void ReadRowsTest(out double TotalReadRec)
159125
sqlDataReader.Close(); // close reader
160126
connection.Close();//close connection
161127
}
162-
TotalReadRec = 1000000.0 / ReadRecord.Elapsed.TotalMilliseconds* 1000.0; // calculate operation per second
128+
TotalReadRec = LOOP_COUNT * 1000.0 / ReadRecord.Elapsed.TotalMilliseconds; // calculate operations per second
163129
}
164130
public void ReadBlobTest(out double TotalReadBlob)
165131
{
@@ -170,7 +136,7 @@ public void ReadBlobTest(out double TotalReadBlob)
170136
//creat stopwatches
171137
Stopwatch ReadRecord = new Stopwatch();
172138
SqlCommand sqlCommand; //create SQLcommand
173-
for (int a = 0; a < 1000; a++)
139+
for (int a = 0; a < LOOP_COUNT; a++)
174140
{
175141
connection.Open();//open connection
176142
sqlCommand = new SqlCommand("SELECT ID,Description, BLOB FROM P1 WHERE ID=" + Convert.ToString(a), connection);//create query
@@ -186,7 +152,7 @@ public void ReadBlobTest(out double TotalReadBlob)
186152
sqlDataReader.Close();
187153
connection.Close();
188154
}
189-
TotalReadBlob = 1000000.0 / ReadRecord.Elapsed.TotalMilliseconds * 1000.0;
155+
TotalReadBlob = LOOP_COUNT * 1000.0 / ReadRecord.Elapsed.TotalMilliseconds;
190156

191157
}
192158
public void WriteBlobTest(out double myBlobWrite)
@@ -197,7 +163,7 @@ public void WriteBlobTest(out double myBlobWrite)
197163
SqlConnection connection = new SqlConnection(connstr); //create SQL Connection
198164
connection.Open(); //open connection
199165
SqlCommand sqlCommand;
200-
for (int a = 0; a < 1000; a++)
166+
for (int a = 0; a < LOOP_COUNT; a++)
201167
{
202168
sqlCommand = new SqlCommand( "select * from P1",connection); //create query
203169
sqlCommand.CommandText = "UPDATE P1 SET BLOB=@BLOB WHERE ID=" + Convert.ToString(a);
@@ -208,7 +174,7 @@ public void WriteBlobTest(out double myBlobWrite)
208174
sqlCommand.Parameters.Clear();
209175
}
210176
connection.Close();
211-
myBlobWrite = 1000.0 / BlobWrite.Elapsed.TotalMilliseconds * 1000; // calculate operations per second
177+
myBlobWrite = LOOP_COUNT * 1000.0 / BlobWrite.Elapsed.TotalMilliseconds; // calculate operations per second
212178
}
213179
public void Cleanup()
214180
{

SQLBench/FileTests.cs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,95 +13,102 @@ namespace SQLBench
1313
//
1414
class FileTests
1515
{
16+
const int RECORD_COUNT = 100000;
17+
const int RECORD_SIZE = 512;
18+
const int LOOP_COUNT_A = 500000;
19+
const int LOOP_COUNT_B = 100;
20+
1621
//Create all the timers
1722
Random intrand;
1823
byte[] array;
1924
public string path;
2025
public FileTests()
2126
{
2227
intrand = new Random();//create random seed
23-
array = new byte[512];//create byte array of 512
24-
path = Environment.CurrentDirectory + "\\test123.bin";//create path for file manipulation 4
28+
array = new byte[RECORD_SIZE];//create byte array of 512
29+
path = Environment.CurrentDirectory + @"\test123.bin"; //create path for file manipulation 4
2530
}
2631
public string createFile()
2732
{
2833
//Create stopwatch to track time
2934
Stopwatch createfile = new Stopwatch();
3035
createfile.Start();
31-
FileStream fileStream1 = System.IO.File.Create(path, 512, FileOptions.RandomAccess);//file stream array
36+
FileStream fileStream1 = System.IO.File.Create(path, RECORD_SIZE, FileOptions.RandomAccess); //file stream array
3237
//loop file stream write
33-
for(int a =0;a<100000;a++)
38+
for(int a = 0; a < RECORD_COUNT; a++)
3439
{
35-
fileStream1.Write(array, 0, 512);
40+
fileStream1.Write(array, 0, RECORD_SIZE);
3641
}
3742
fileStream1.Close();
3843
createfile.Stop();
3944
TimeSpan mytime = createfile.Elapsed; //get time elapsed
40-
return (mytime.TotalMilliseconds / 5.0).ToString("#,##0");//calculate operations er second
45+
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");//calculate operations per second
4146
}
4247
public string readFile()
4348
{
4449
//Read File
4550
Stopwatch READfile = new Stopwatch();//create timer
4651
READfile.Start();//Start timer
47-
FileStream fileStream3 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, 512, FileOptions.SequentialScan); //reate file stream
52+
FileStream fileStream3 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, RECORD_SIZE, FileOptions.SequentialScan); //reate file stream
4853
//loop for stream reader
49-
for (int a = 0; a < 100000; a++)
54+
for (int a = 0; a < RECORD_COUNT; a++)
5055
{
51-
fileStream3.Read(array, 0, 512);
56+
fileStream3.Read(array, 0, RECORD_SIZE);
5257
}
5358
fileStream3.Close();
5459
READfile.Stop();
5560
TimeSpan mytime = READfile.Elapsed;//get time elapsed
56-
return (500000.0/mytime.TotalMilliseconds * 1000.0).ToString("#,##0");//caclupate operations per second
61+
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");//caclupate operations per second
5762
}
5863
public string SequenceWrite()
5964
{
6065
//write sequecially
6166
Stopwatch SeqWritefile = new Stopwatch();//create timer
6267
SeqWritefile.Start();//start timer
63-
FileStream fileStream4 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 512, FileOptions.SequentialScan);//create strim with sequential option
68+
FileStream fileStream4 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None, RECORD_SIZE, FileOptions.SequentialScan);//create strim with sequential option
6469
//loop writing a file sequentially
65-
for (int a = 0; a < 100000; a++)
70+
for (int a = 0; a < RECORD_COUNT; a++)
6671
{
67-
fileStream4.Write(array, 0, 512);
72+
fileStream4.Write(array, 0, RECORD_SIZE);
6873
}
6974
fileStream4.Close();//close stream
7075
SeqWritefile.Stop();//stop timer
7176
TimeSpan mytime = SeqWritefile.Elapsed;//get elapsed time
72-
return (500000.0 / mytime.TotalMilliseconds*1000.0).ToString("#,##0");//calculate operations per second
77+
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");//calculate operations per second
7378
}
7479
public string randomRead()
7580
{
7681
//Random File Reads.
7782
Stopwatch RndReadfile = new Stopwatch();//create timer
7883
RndReadfile.Start();//Start timer
79-
FileStream fileStream5 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, 512, FileOptions.RandomAccess);//create stream with random access option
84+
FileStream fileStream5 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, RECORD_SIZE, FileOptions.RandomAccess);//create stream with random access option
8085
//loop while randomly reading parts of the file
81-
for (int a = 0; a < 100000; a++)
86+
for (int a = 0; a < RECORD_COUNT; a++)
8287
{
83-
fileStream5.Seek((long)Math.Round((512f * (double)(intrand.Next() * 100000f))), SeekOrigin.Begin);
84-
fileStream5.Read(array, 0, 512);
88+
long SeekPos = RECORD_SIZE * intrand.Next(RECORD_COUNT); //(long)Math.Round((512f * (double)(intrand.Next() * 100000f)));
89+
fileStream5.Seek(SeekPos, SeekOrigin.Begin);
90+
fileStream5.Read(array, 0, RECORD_SIZE);
8591
}
8692
fileStream5.Close();
8793
RndReadfile.Stop();
8894
TimeSpan mytime = RndReadfile.Elapsed;
89-
return (5000.0 / mytime.TotalMilliseconds*1000.0).ToString("#.##0");
95+
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");
9096
}
9197
public string randomWrite()
9298
{
9399
Stopwatch RndWritefile = new Stopwatch();
94100
RndWritefile.Start();
95-
FileStream fileStream6 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 512, FileOptions.RandomAccess);
96-
for (int a = 0; a < 100; a++)
101+
FileStream fileStream6 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None, RECORD_SIZE, FileOptions.RandomAccess);
102+
for (int a = 0; a < RECORD_COUNT; a++)
97103
{
98-
fileStream6.Seek((long)Math.Round((512f * (double)(intrand.Next() * 100000f))), SeekOrigin.Begin);
99-
fileStream6.Write(array, 0, 512);
104+
long SeekPos = RECORD_SIZE * intrand.Next(RECORD_COUNT); //(long)Math.Round((512f * (double)(intrand.Next() * 100000f)));
105+
fileStream6.Seek(SeekPos, SeekOrigin.Begin);
106+
fileStream6.Write(array, 0, RECORD_SIZE);
100107
}
101108
fileStream6.Close();
102109
RndWritefile.Stop();
103110
TimeSpan mytime = RndWritefile.Elapsed;
104-
return (5000.0 / mytime.TotalMilliseconds*1000.0).ToString("#.##0");
111+
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");
105112
}
106113
}
107114
}

0 commit comments

Comments
 (0)