c#測試本機sql運算速度的代碼示例分享
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection();
SqlCommand comm = new SqlCommand();
DateTime t1, t2;
int count = 10000; //循環(huán)次數(shù)
string times;
conn.ConnectionString = "Data Source=.;Initial Catalog=Server;Integrated Security=True";
comm.CommandText = "insert into test (Cid,Cvalue) values('1','1')"; //數(shù)據(jù)插入
comm.Connection = conn;
Console.WriteLine("開始插入數(shù)據(jù)\r\n開始時間:" +(t1=DateTime.Now).ToLongTimeString());
try
{
conn.Open();
for (int i = 1; i <= count; i++)
{
comm.ExecuteNonQuery(); //執(zhí)行查詢
}
Console.WriteLine("結(jié)束時間:" + (t2 = DateTime.Now).ToLongTimeString());
times = GetTimeSpan(t1, t2).ToString();
Console.WriteLine("持續(xù)時間:" + times.Substring(0, times.LastIndexOf(".") + 4));
Console.WriteLine("本次測試總共對數(shù)據(jù)庫進行了" + count + "次數(shù)據(jù)插入操作!");
//comm.CommandText = "delete from test";
//comm.ExecuteNonQuery();
//Console.WriteLine("測試數(shù)據(jù)已刪除");
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
finally
{
comm = null;
conn.Close();
conn.Close();
}
Console.ReadKey();
}
/// <summary>
/// 返回兩個時間對象的時間間隔
/// </summary>
private static TimeSpan GetTimeSpan(DateTime t1, DateTime t2)
{
DateTime t3;
if (DateTime.Compare(t1, t2) == 1)
{
t3 = t1;
t1 = t2;
t2 = t3;
}
return t2.Subtract(t1);
}
}
}
- 使用 BenchmarkDotNet 對 C# 代碼進行基準測試
- C#建立測試用例系統(tǒng)的示例代碼
- 關(guān)于Unity C# Mathf.Abs()取絕對值性能測試詳解
- C#使用base64對字符串進行編碼和解碼的測試
- C#使用String和StringBuilder運行速度測試及各自常用方法簡介
- 詳解C# WebApi 接口測試工具:WebApiTestClient
- c# 插入數(shù)據(jù)效率測試(mongodb)
- 京東聯(lián)盟C#接口測試示例分享
- C#/.Net 中快速批量給SQLite數(shù)據(jù)庫插入測試數(shù)據(jù)
- C#代碼性能測試類(簡單實用)
- C#控制臺下測試多線程的方法
- c#測試反射性能示例
- C# 單元測試全解析
相關(guān)文章
C#歸并排序的實現(xiàn)方法(遞歸,非遞歸,自然歸并)
C#歸并排序的實現(xiàn)方法(遞歸,非遞歸,自然歸并),需要的朋友可以參考一下2013-04-04
C#實現(xiàn)把圖片轉(zhuǎn)換成二進制以及把二進制轉(zhuǎn)換成圖片的方法示例
這篇文章主要介紹了C#實現(xiàn)把圖片轉(zhuǎn)換成二進制以及把二進制轉(zhuǎn)換成圖片的方法,結(jié)合具體實例形式分析了基于C#的圖片與二進制相互轉(zhuǎn)換以及圖片保存到數(shù)據(jù)庫的相關(guān)操作技巧,需要的朋友可以參考下2017-06-06
C#設計模式之Observer觀察者模式解決牛頓童鞋成績問題示例
這篇文章主要介紹了C#設計模式之Observer觀察者模式解決牛頓童鞋成績問題,簡單講述了觀察者模式的原理并結(jié)合具體實例形式分析了使用觀察者模式解決牛頓童鞋成績問題的具體步驟相關(guān)操作技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-09-09
C#遍歷得到checkboxlist選中值和設置選中項的代碼
這篇文章主要介紹了C#遍歷得到checkboxlist選中值和設置選中項的代碼,代碼簡單易懂,具有參考借鑒價值,需要的朋友可以參考下2016-08-08

