Skip to content

Commit

Permalink
SQL Bench Code Review and Changes
Browse files Browse the repository at this point in the history
Removed form mode. The tool is just a console app as of this build.
  • Loading branch information
Malcolm-Stewart committed Oct 12, 2021
1 parent 5f607fb commit d0ec6ea
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 1,817 deletions.
Binary file modified SQLBench/.vs/SQLBench/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified SQLBench/.vs/SQLBench/v15/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified SQLBench/.vs/SQLBench/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
18 changes: 11 additions & 7 deletions SQLBench/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace SQLBench
// string result = Parse(args) - once, result contains error message or "" if okay
// ArrayList List = GetArgs(argname) - once per arg, returns an ArrayList of 0..n CommandlineArgs
//
// Arguments can have the following prioperties:
// Arguments can have the following properties:
//
// Case sensitive or case-insensitive
// Required or optional
Expand All @@ -26,12 +26,16 @@ namespace SQLBench
//
// appname.exe filename [-out filename] [-g value] [-G] -h value [-flags value [-flags value [...]]]
//
// cp.AddRule(new ArgRule("", true, false, true, true)); // file name is required
// cp.AddRule(new ArgRule("flags", true, true, true, false)); // flags is optional but may appear more than once
// cp.AddRule(new ArgRule("out", true, false, true, false)); // out is optional but may only appear once
// cp.AddRule(new ArgRule("g", true, false, false, false)); // g is optional and case-sensitive
// cp.AddRule(new ArgRule("G", false, false, false, false)); // G is optional and takes no value and is case sensitive
// cp.AddRule(new ArgRule("h", true, false, true, true)); // h is required and takes an argument
// ArgRule(string argName, bool hasValue, bool allowDuplicates = false, bool caseInsensitive = true, bool required = true)
//
// ignore
// name value dup case req
// cp.AddRule(new ArgRule("", true, false, true, true)); // file name is required
// cp.AddRule(new ArgRule("flags", true, true, true, false)); // flags is optional but may appear more than once
// cp.AddRule(new ArgRule("out", true, false, true, false)); // out is optional but may only appear once
// cp.AddRule(new ArgRule("g", true, false, false, false)); // g is optional and case-sensitive
// cp.AddRule(new ArgRule("G", false, false, false, false)); // G is optional and takes no value and is case sensitive
// cp.AddRule(new ArgRule("h", true, false, true, true)); // h is required and takes an argument
//
// argements can appear in any order, as long as name/value pairs are adjacent
// arguments other than -g and -G are case-insensitive
Expand Down
68 changes: 17 additions & 51 deletions SQLBench/DBTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.IO;
using System.Data.SqlClient;
using System.Data;
using System.Diagnostics;
Expand All @@ -16,48 +14,16 @@ namespace SQLBench
//
class DBTests
{
const int OPEN_COUNT = 1000;
const int LOOP_COUNT = 1000;
public string connstr = "";
public DBTests(string connStr)
{
connstr = connStr;
//if (Source == "File")//this is command line
//{
// if (myFile != "")
// {
// if (File.Exists(myFile))
// {
// Console.WriteLine(myFile);
// ReadFile(myFile);
// }
// else
// {
// connstr.Add(myFile);
// }
// }
// else
// {
// connstr.Add("server=(local);database=Tempdb;Integrated Security=SSPI");
// }
//}
//if (Source == "TextBox")//this comes from the GUI interface
//{
// string[] strArray = myFile.Split('\r');
// foreach(string a in strArray)
// {
// connstr.Add(a);
// }
//}
if (connstr.ToLower().Contains("pooling") == false) connstr += ";Pooling=false";
}
//private void ReadFile(string myFile)
//{
// //Stream lines from the file to the list
// string line;
// StreamReader SR = new StreamReader(myFile);
// while((line = SR.ReadLine()) != null)
// {
// connstr.Add(line);
// }
//}


public void Test()
{
//command line.
Expand All @@ -73,7 +39,7 @@ public void ConnTest(out double opentotal, out double closetotal)
SqlConnection connection = new SqlConnection(connstr);
opentotal = 0.0;
closetotal = 0.0;
for (int a = 0; a < 1000; a++)
for (int a = 0; a < OPEN_COUNT; a++)
{
// start timers
//OPen connection
Expand All @@ -86,9 +52,9 @@ public void ConnTest(out double opentotal, out double closetotal)
connection.Close();
closeconn.Stop();
}
//calculate ops er second
opentotal = 4000.0 / openconn.Elapsed.TotalMilliseconds*1000;
closetotal = 4000.0 /closeconn.Elapsed.TotalMilliseconds*1000;
//calculate ops per second
opentotal = OPEN_COUNT * 1000.0 / openconn.Elapsed.TotalMilliseconds;
closetotal = OPEN_COUNT * 1000.0 / closeconn.Elapsed.TotalMilliseconds;

}
public void InsertRow(out double myInsert)
Expand Down Expand Up @@ -122,7 +88,7 @@ public void InsertRow(out double myInsert)
sqlCommand.ExecuteNonQuery(); //execute query
connection.Close(); // close connection

for (int a = 0; a < 1000; a++)
for (int a = 0; a < LOOP_COUNT; a++)
{
//insert concat string
connection.Open(); //open connection
Expand All @@ -132,7 +98,7 @@ public void InsertRow(out double myInsert)
myInsertwatch.Stop(); //stop time
connection.Close(); // close connection
}
myInsert = 1000.0 / myInsertwatch.Elapsed.TotalMilliseconds* 1000; // Caclulate ops er second
myInsert = LOOP_COUNT * 1000.0 / myInsertwatch.Elapsed.TotalMilliseconds; // Caclulate ops per second
}
public void ReadRowsTest(out double TotalReadRec)
{
Expand All @@ -144,7 +110,7 @@ public void ReadRowsTest(out double TotalReadRec)
//creat stopwatches
Stopwatch ReadRecord = new Stopwatch();
SqlCommand sqlCommand;//create sqlcommand
for(int a = 0;a<1000;a++)
for(int a = 0; a < LOOP_COUNT; a++)
{
connection.Open(); //open connectoin
sqlCommand = new SqlCommand("SELECT ID,Description FROM P1", connection); //create query
Expand All @@ -159,7 +125,7 @@ public void ReadRowsTest(out double TotalReadRec)
sqlDataReader.Close(); // close reader
connection.Close();//close connection
}
TotalReadRec = 1000000.0 / ReadRecord.Elapsed.TotalMilliseconds* 1000.0; // calculate operation per second
TotalReadRec = LOOP_COUNT * 1000.0 / ReadRecord.Elapsed.TotalMilliseconds; // calculate operations per second
}
public void ReadBlobTest(out double TotalReadBlob)
{
Expand All @@ -170,7 +136,7 @@ public void ReadBlobTest(out double TotalReadBlob)
//creat stopwatches
Stopwatch ReadRecord = new Stopwatch();
SqlCommand sqlCommand; //create SQLcommand
for (int a = 0; a < 1000; a++)
for (int a = 0; a < LOOP_COUNT; a++)
{
connection.Open();//open connection
sqlCommand = new SqlCommand("SELECT ID,Description, BLOB FROM P1 WHERE ID=" + Convert.ToString(a), connection);//create query
Expand All @@ -186,7 +152,7 @@ public void ReadBlobTest(out double TotalReadBlob)
sqlDataReader.Close();
connection.Close();
}
TotalReadBlob = 1000000.0 / ReadRecord.Elapsed.TotalMilliseconds * 1000.0;
TotalReadBlob = LOOP_COUNT * 1000.0 / ReadRecord.Elapsed.TotalMilliseconds;

}
public void WriteBlobTest(out double myBlobWrite)
Expand All @@ -197,7 +163,7 @@ public void WriteBlobTest(out double myBlobWrite)
SqlConnection connection = new SqlConnection(connstr); //create SQL Connection
connection.Open(); //open connection
SqlCommand sqlCommand;
for (int a = 0; a < 1000; a++)
for (int a = 0; a < LOOP_COUNT; a++)
{
sqlCommand = new SqlCommand( "select * from P1",connection); //create query
sqlCommand.CommandText = "UPDATE P1 SET BLOB=@BLOB WHERE ID=" + Convert.ToString(a);
Expand All @@ -208,7 +174,7 @@ public void WriteBlobTest(out double myBlobWrite)
sqlCommand.Parameters.Clear();
}
connection.Close();
myBlobWrite = 1000.0 / BlobWrite.Elapsed.TotalMilliseconds * 1000; // calculate operations per second
myBlobWrite = LOOP_COUNT * 1000.0 / BlobWrite.Elapsed.TotalMilliseconds; // calculate operations per second
}
public void Cleanup()
{
Expand Down
55 changes: 31 additions & 24 deletions SQLBench/FileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,95 +13,102 @@ namespace SQLBench
//
class FileTests
{
const int RECORD_COUNT = 100000;
const int RECORD_SIZE = 512;
const int LOOP_COUNT_A = 500000;
const int LOOP_COUNT_B = 100;

//Create all the timers
Random intrand;
byte[] array;
public string path;
public FileTests()
{
intrand = new Random();//create random seed
array = new byte[512];//create byte array of 512
path = Environment.CurrentDirectory + "\\test123.bin";//create path for file manipulation 4
array = new byte[RECORD_SIZE];//create byte array of 512
path = Environment.CurrentDirectory + @"\test123.bin"; //create path for file manipulation 4
}
public string createFile()
{
//Create stopwatch to track time
Stopwatch createfile = new Stopwatch();
createfile.Start();
FileStream fileStream1 = System.IO.File.Create(path, 512, FileOptions.RandomAccess);//file stream array
FileStream fileStream1 = System.IO.File.Create(path, RECORD_SIZE, FileOptions.RandomAccess); //file stream array
//loop file stream write
for(int a =0;a<100000;a++)
for(int a = 0; a < RECORD_COUNT; a++)
{
fileStream1.Write(array, 0, 512);
fileStream1.Write(array, 0, RECORD_SIZE);
}
fileStream1.Close();
createfile.Stop();
TimeSpan mytime = createfile.Elapsed; //get time elapsed
return (mytime.TotalMilliseconds / 5.0).ToString("#,##0");//calculate operations er second
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");//calculate operations per second
}
public string readFile()
{
//Read File
Stopwatch READfile = new Stopwatch();//create timer
READfile.Start();//Start timer
FileStream fileStream3 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, 512, FileOptions.SequentialScan); //reate file stream
FileStream fileStream3 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, RECORD_SIZE, FileOptions.SequentialScan); //reate file stream
//loop for stream reader
for (int a = 0; a < 100000; a++)
for (int a = 0; a < RECORD_COUNT; a++)
{
fileStream3.Read(array, 0, 512);
fileStream3.Read(array, 0, RECORD_SIZE);
}
fileStream3.Close();
READfile.Stop();
TimeSpan mytime = READfile.Elapsed;//get time elapsed
return (500000.0/mytime.TotalMilliseconds * 1000.0).ToString("#,##0");//caclupate operations per second
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");//caclupate operations per second
}
public string SequenceWrite()
{
//write sequecially
Stopwatch SeqWritefile = new Stopwatch();//create timer
SeqWritefile.Start();//start timer
FileStream fileStream4 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 512, FileOptions.SequentialScan);//create strim with sequential option
FileStream fileStream4 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None, RECORD_SIZE, FileOptions.SequentialScan);//create strim with sequential option
//loop writing a file sequentially
for (int a = 0; a < 100000; a++)
for (int a = 0; a < RECORD_COUNT; a++)
{
fileStream4.Write(array, 0, 512);
fileStream4.Write(array, 0, RECORD_SIZE);
}
fileStream4.Close();//close stream
SeqWritefile.Stop();//stop timer
TimeSpan mytime = SeqWritefile.Elapsed;//get elapsed time
return (500000.0 / mytime.TotalMilliseconds*1000.0).ToString("#,##0");//calculate operations per second
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");//calculate operations per second
}
public string randomRead()
{
//Random File Reads.
Stopwatch RndReadfile = new Stopwatch();//create timer
RndReadfile.Start();//Start timer
FileStream fileStream5 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, 512, FileOptions.RandomAccess);//create stream with random access option
FileStream fileStream5 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, RECORD_SIZE, FileOptions.RandomAccess);//create stream with random access option
//loop while randomly reading parts of the file
for (int a = 0; a < 100000; a++)
for (int a = 0; a < RECORD_COUNT; a++)
{
fileStream5.Seek((long)Math.Round((512f * (double)(intrand.Next() * 100000f))), SeekOrigin.Begin);
fileStream5.Read(array, 0, 512);
long SeekPos = RECORD_SIZE * intrand.Next(RECORD_COUNT); //(long)Math.Round((512f * (double)(intrand.Next() * 100000f)));
fileStream5.Seek(SeekPos, SeekOrigin.Begin);
fileStream5.Read(array, 0, RECORD_SIZE);
}
fileStream5.Close();
RndReadfile.Stop();
TimeSpan mytime = RndReadfile.Elapsed;
return (5000.0 / mytime.TotalMilliseconds*1000.0).ToString("#.##0");
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");
}
public string randomWrite()
{
Stopwatch RndWritefile = new Stopwatch();
RndWritefile.Start();
FileStream fileStream6 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 512, FileOptions.RandomAccess);
for (int a = 0; a < 100; a++)
FileStream fileStream6 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None, RECORD_SIZE, FileOptions.RandomAccess);
for (int a = 0; a < RECORD_COUNT; a++)
{
fileStream6.Seek((long)Math.Round((512f * (double)(intrand.Next() * 100000f))), SeekOrigin.Begin);
fileStream6.Write(array, 0, 512);
long SeekPos = RECORD_SIZE * intrand.Next(RECORD_COUNT); //(long)Math.Round((512f * (double)(intrand.Next() * 100000f)));
fileStream6.Seek(SeekPos, SeekOrigin.Begin);
fileStream6.Write(array, 0, RECORD_SIZE);
}
fileStream6.Close();
RndWritefile.Stop();
TimeSpan mytime = RndWritefile.Elapsed;
return (5000.0 / mytime.TotalMilliseconds*1000.0).ToString("#.##0");
return (RECORD_COUNT * 1000.0f / mytime.TotalMilliseconds).ToString("#,##0");
}
}
}
Loading

0 comments on commit d0ec6ea

Please sign in to comment.