Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication3
- {
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Diagnostics;
- using System.Globalization;
- using System.IO;
- using System.Linq.Expressions;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Threading;
- using System.Xml.Linq;
- using Microsoft.ApplicationServer.Caching;
- class Program
- {
- private static readonly DataCache cache = new DataCacheFactory().GetDefaultCache();
- private static SqlConnection cn = new SqlConnection("Data Source=localhost; Initial Catalog=Test; Integrated Security=True;");
- private static SqlCommand command = new SqlCommand("Select Value from Cache where [Key] = @key", cn);
- private static int maxValue = 100000;
- private const string Region = "Test";
- private const string data = "dfla jfaslkdfjs;kjsad;fl sopriwurowurpwqi urwrioq weropw ruwqropi wqrop iwrowi urworiu woruiw rowiurw oruiuw rwskldfjsakf,er wq';erkl 'rw;qklr w'ru woeirupqcoinrpo cnopiwur nqwoeri vuqw quw vopwruq wporq wvueporiu pwouri ouq hqerkqw lckbqwrqw oprui2 r2iou3 p2o uiurm2poiur21po3i1 2opui314 mop23ui4214 m129-4m812-480 cm;sokjf pos ciq[w qf'[wfiw'[epiq[riw[tiopq tql hqkljncr123oiu12priu2 3h4jh f'alskf asqwiotu qwuiqwerqwrlkh ";
- static void Main(string[] args)
- {
- cache.CreateRegion(Region);
- cn.Open();
- command.Parameters.Add("@key", SqlDbType.NVarChar);
- var sw = new Stopwatch();
- sw.Start();
- FillFabric();
- sw.Stop();
- Console.WriteLine("Fill cache: " + sw.ElapsedMilliseconds);
- sw.Restart();
- FillSql();
- sw.Stop();
- Console.WriteLine("Fill sql: " + sw.ElapsedMilliseconds);
- sw.Restart();
- RandomRead(ReadCache);
- sw.Stop();
- Console.WriteLine("Read cache: " + sw.ElapsedMilliseconds);
- sw.Restart();
- RandomRead(ReadSql);
- sw.Stop();
- Console.WriteLine("Read sql: " + sw.ElapsedMilliseconds);
- Console.Read();
- }
- private static void ReadSql(string key)
- {
- command.Parameters["@key"].Value = key;
- command.ExecuteScalar();
- }
- private static void ReadCache(string key)
- {
- cache.Get(key, Region);
- }
- private static void RandomRead(Action<string> action)
- {
- for (int i = 0; i < maxValue; i++)
- {
- var rnd = new Random().Next(0, maxValue);
- action(rnd.ToString());
- }
- }
- private static void FillFabric()
- {
- for (int i = 0; i < maxValue; i++)
- {
- cache.Put(i.ToString(), data + i, Region);
- }
- }
- private static void FillSql()
- {
- using (var cmd = new SqlCommand())
- {
- cmd.CommandType = CommandType.Text;
- cmd.CommandTimeout = 60000;
- cmd.Connection = cn;
- cmd.Parameters.Add("@p1", SqlDbType.NVarChar);
- cmd.Parameters.Add("@p2", SqlDbType.NVarChar);
- for (int i = 0; i < maxValue; i++)
- {
- cmd.CommandText = "insert into Cache VALUES (@p1, @p2)";
- cmd.Parameters["@p1"].Value = i.ToString();
- cmd.Parameters["@p2"].Value = data + i;
- cmd.ExecuteNonQuery();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement