DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
PerformanceTest.cs
Go to the documentation of this file.
1 using System;
2 
3 using Deveel.Data.Client;
4 
5 using NUnit.Framework;
6 
7 namespace Deveel.Data {
8  [TestFixture]
9  public class PerformanceTest : TestBase {
10  protected override void OnSetUp() {
11  DeveelDbCommand command = Connection.CreateCommand();
12  command.CommandText = "CREATE TABLE IF NOT EXISTS TestTable (" +
13  " id IDENTITY," +
14  " inc INTEGER," +
15  " var_name VARCHAR(200)" +
16  ")";
17  command.ExecuteNonQuery();
18  }
19 
20  protected override void OnTearDown() {
21  DeveelDbCommand command = Connection.CreateCommand("DROP TABLE TestTable");
22  command.ExecuteNonQuery();
23  }
24 
25  [Test]
27  // we deisable the AUTO_COMMIT flag for such this operation
28  DeveelDbTransaction transaction = Connection.BeginTransaction();
29 
30  DeveelDbCommand command;
31 
32  DateTime start = DateTime.Now;
33 
34  for (int i = 0; i < 1000; i++) {
35  command = Connection.CreateCommand();
36  command.CommandText = "INSERT INTO TestTable (inc, var_name) VALUES (?, ?)";
37  command.Parameters.Add(i);
38  command.Parameters.Add("var_" + i);
39  command.ExecuteNonQuery();
40  }
41 
42  DateTime end = DateTime.Now;
43  Console.Out.WriteLine("Inserted 1000 rows in {0}.", (end - start));
44 
45  command = Connection.CreateCommand("SELECT COUNT(*) FROM TestTable");
46  BigNumber count = (BigNumber) command.ExecuteScalar();
47 
48  Assert.AreEqual(1000, count.ToInt32(), "Not all the rows were inserted");
49 
50  start = DateTime.Now;
51 
52  transaction.Rollback();
53 
54  end = DateTime.Now;
55 
56  Console.Out.WriteLine("Rolled-back in {0}", (end - start));
57 
58  command = Connection.CreateCommand("SELECT COUNT(*) FROM TestTable");
59  count = (BigNumber)command.ExecuteScalar();
60 
61  Assert.AreEqual(0, count, "After rollback there shouldn't be any rows in the table.");
62  }
63 
64  [Test]
66  // we deisable the AUTO_COMMIT flag for such this operation
67  DeveelDbTransaction transaction = Connection.BeginTransaction();
68 
69  DeveelDbCommand command = Connection.CreateCommand();;
70 
71  DateTime start = DateTime.Now;
72 
73  for (int i = 0; i < 1000; i++) {
74  command.CommandText = "INSERT INTO TestTable (inc, var_name) VALUES (?, ?)";
75  command.Parameters.Add(i);
76  command.Parameters.Add("var_" + i);
77  command.ExecuteNonQuery();
78  }
79 
80  DateTime end = DateTime.Now;
81  Console.Out.WriteLine("Inserted 1000 rows in {0}.", (end - start));
82 
83  start = DateTime.Now;
84 
85  transaction.Commit();
86 
87  end = DateTime.Now;
88 
89  Console.Out.WriteLine("Committed in {0}.", (end - start));
90 
91  command = Connection.CreateCommand("SELECT COUNT(*) FROM TestTable");
92  BigNumber count = (BigNumber)command.ExecuteScalar();
93 
94  Console.Out.WriteLine("Numer of rows inserted into TestTable : {0}", count);
95  }
96  }
97 }
new DeveelDbParameterCollection Parameters