// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Data; using System.Data.Common; namespace E { public class Program { private const int NREC = 10000; private static void Test(IDbConnection con, bool unicode) { using(IDbCommand cre = con.CreateCommand()) { if(unicode) { cre.CommandText = "CREATE TABLE test (f1 NVARCHAR(10) NOT NULL PRIMARY KEY, f2 NVARCHAR(50))"; } else { cre.CommandText = "CREATE TABLE test (f1 VARCHAR(10) NOT NULL PRIMARY KEY, f2 VARCHAR(50))"; } cre.ExecuteNonQuery(); } using(IDbCommand ins = con.CreateCommand()) { ins.CommandText = "INSERT INTO test VALUES(@f1, @f2)"; IDbDataParameter p1 = ins.CreateParameter(); p1.ParameterName = "@f1"; p1.DbType = DbType.String; p1.Size = 10; ins.Parameters.Add(p1); IDbDataParameter p2 = ins.CreateParameter(); p2.ParameterName = "@f2"; p2.DbType = DbType.String; p2.Size = 50; ins.Parameters.Add(p2); for(int i = 0; i < NREC; i++) { ((IDbDataParameter)ins.Parameters["@f1"]).Value = "K" + i; ((IDbDataParameter)ins.Parameters["@f2"]).Value = "Dette er bare en lille test"; ins.ExecuteNonQuery(); } } using(IDbCommand drp = con.CreateCommand()) { drp.CommandText = "DROP TABLE test"; drp.ExecuteNonQuery(); } } private static void Test(string name, string prov, string constr, bool unicode) { DateTime t1 = DateTime.Now; DbProviderFactory dbf = DbProviderFactories.GetFactory(prov); using(IDbConnection con = dbf.CreateConnection()) { con.ConnectionString = constr; con.Open(); Test(con, unicode); } DateTime t2 = DateTime.Now; Console.WriteLine(name + " : " + (t2 - t1).TotalSeconds.ToString("0.00") + " seconds"); } private static void Test() { Test("MS Access", "System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=SpeedTest.mdb", false); Test("SQLite", "System.Data.SQLite", "Data Source=SpeedTest.db;Version=3;", false); Test("SQLServer CE", "System.Data.SqlServerCe", "Data Source=SpeedTest.sdf", true); Test("Firebird", "FirebirdSql.Data.FirebirdClient", "ServerType=1;Database=SpeedTest.fdb", false); } private const int REP = 3; public static void Main(string[] args) { for(int i = 0; i < REP; i++) { Test(); } } } }