c#測(cè)試本機(jī)sql運(yùn)算速度的代碼示例分享
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("開(kāi)始插入數(shù)據(jù)\r\n開(kāi)始時(shí)間:" +(t1=DateTime.Now).ToLongTimeString());
try
{
conn.Open();
for (int i = 1; i <= count; i++)
{
comm.ExecuteNonQuery(); //執(zhí)行查詢(xún)
}
Console.WriteLine("結(jié)束時(shí)間:" + (t2 = DateTime.Now).ToLongTimeString());
times = GetTimeSpan(t1, t2).ToString();
Console.WriteLine("持續(xù)時(shí)間:" + times.Substring(0, times.LastIndexOf(".") + 4));
Console.WriteLine("本次測(cè)試總共對(duì)數(shù)據(jù)庫(kù)進(jìn)行了" + count + "次數(shù)據(jù)插入操作!");
//comm.CommandText = "delete from test";
//comm.ExecuteNonQuery();
//Console.WriteLine("測(cè)試數(shù)據(jù)已刪除");
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
finally
{
comm = null;
conn.Close();
conn.Close();
}
Console.ReadKey();
}
/// <summary>
/// 返回兩個(gè)時(shí)間對(duì)象的時(shí)間間隔
/// </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 對(duì) C# 代碼進(jìn)行基準(zhǔn)測(cè)試
- C#建立測(cè)試用例系統(tǒng)的示例代碼
- 關(guān)于Unity C# Mathf.Abs()取絕對(duì)值性能測(cè)試詳解
- C#使用base64對(duì)字符串進(jìn)行編碼和解碼的測(cè)試
- C#使用String和StringBuilder運(yùn)行速度測(cè)試及各自常用方法簡(jiǎn)介
- 詳解C# WebApi 接口測(cè)試工具:WebApiTestClient
- c# 插入數(shù)據(jù)效率測(cè)試(mongodb)
- 京東聯(lián)盟C#接口測(cè)試示例分享
- C#/.Net 中快速批量給SQLite數(shù)據(jù)庫(kù)插入測(cè)試數(shù)據(jù)
- C#代碼性能測(cè)試類(lèi)(簡(jiǎn)單實(shí)用)
- C#控制臺(tái)下測(cè)試多線程的方法
- c#測(cè)試反射性能示例
- C# 單元測(cè)試全解析
相關(guān)文章
C#實(shí)現(xiàn)Excel動(dòng)態(tài)生成PivotTable
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)Excel動(dòng)態(tài)生成PivotTable的相關(guān)方法,感興趣的小伙伴們可以參考一下2016-04-04C#通過(guò)反射獲取當(dāng)前工程中所有窗體并打開(kāi)的方法
這篇文章主要介紹了C#通過(guò)反射獲取當(dāng)前工程中所有窗體并打開(kāi)的方法,涉及C#針對(duì)窗體的獲取與顯示等操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08基于Unity編寫(xiě)一個(gè)九宮格抽獎(jiǎng)軟件
這篇文章主要為大家介紹了如何利用Unity編寫(xiě)一個(gè)年會(huì)抽獎(jiǎng)軟件,還能設(shè)置中獎(jiǎng)概率。文中的示例代碼講解詳細(xì),感興趣的可以了解一下2022-03-03C# TreeView讀取數(shù)據(jù)庫(kù)簡(jiǎn)單實(shí)例
這篇文章主要介紹了2013-12-12RegexOptions.IgnoreCase正則表達(dá)式替換,忽略大小寫(xiě)
RegexOptions.IgnoreCase正則表達(dá)式替換,忽略大小寫(xiě),需要的朋友可以參考一下2013-03-03C#中通過(guò)Command模式實(shí)現(xiàn)Redo/Undo方案
這篇文章介紹了C#中通過(guò)Command模式實(shí)現(xiàn)Redo/Undo方案的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06簡(jiǎn)單了解C#設(shè)計(jì)模式編程中的橋接模式
這篇文章主要介紹了C#設(shè)計(jì)模式編程中的橋接模式,橋接模式經(jīng)常應(yīng)用于解耦邏輯層與數(shù)據(jù)操作層,需要的朋友可以參考下2016-02-02