// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Collections.Generic; using System.Data.Odbc; namespace cache.IgniteOdbc.Performance { public class Program { private static void Put(OdbcConnection con, String key, int? value) { using(OdbcCommand cmd = new OdbcCommand("MERGE INTO performance_cache(ckey,cvalue) VALUES(?,?)", con)) { cmd.Parameters.Add(new OdbcParameter(":key", OdbcType.VarChar, 16)); cmd.Parameters.Add(new OdbcParameter(":value", OdbcType.Int)); cmd.Parameters[":key"].Value = key; cmd.Parameters[":value"].Value = value; cmd.ExecuteNonQuery(); } } private const int N = 10000; private static void Test(OdbcConnection con) { // put speed DateTime dt1 = DateTime.Now; for(int i = 0; i < N; i++) { Put(con, "K#" + (i + 1), i + 1); } DateTime dt2 = DateTime.Now; Console.WriteLine("{0} puts per second", N * 1000 / (int)((dt2 - dt1).TotalMilliseconds)); } private const int REP = 5; public static void Main(string[] args) { using (OdbcConnection con = new OdbcConnection("Dsn=ARNEPC4_IGNITE")) { con.Open(); using(OdbcCommand cmd = new OdbcCommand("CREATE TABLE IF NOT EXISTS performance_cache (ckey VARCHAR(16) NOT NULL, cvalue INTEGER NOT NULL, PRIMARY KEY(ckey))", con)) { cmd.ExecuteNonQuery(); } for(int i = 0; i < REP; i++) { Test(con); } } } } }