using System;
namespace StrTest
{
class Program
{
//定义3个字符串 以便测试在多种情况下 下面6种判断方法的速度
public static string strTest01 = "";
public static string strTest02 = string.Empty;
public static string strTest03 = "0123456789";
public static DateTime start, end; //定义开始时间 和 结束时间
public static TimeSpan ts; //定义两个时间的间隔
//**********************对strTest使用6种测试方法*****************************
public static void Test(string strTest)
{
//string == ""
start = DateTime.Now;
for (int counter = 0; counter <= 100000000; counter++)
{
if (strTest == "")
{
}
}
end = DateTime.Now;
ts = end - start;
Console.WriteLine("string == /"/" 时间消耗为 " + ts.TotalSeconds + " 秒");
//string.Equals("")
start = DateTime.Now;
for (int counter = 0; counter <= 100000000; counter++)
{
if (strTest.Equals(""))
{
}
}
end = DateTime.Now;
ts = end - start;
Console.WriteLine("string.Equals(/"/") 时间消耗为 " + ts.TotalSeconds + " 秒");
//string == stirng.Empty
start = DateTime.Now;
for (int counter = 0; counter <= 100000000; counter++)
{
if (strTest == string.Empty)
{
}
}
end = DateTime.Now;
ts = end - start;
Console.WriteLine("string == string.Empty 时间消耗为 " + ts.TotalSeconds + " 秒");
//string.Equals(string.Empty)
start = DateTime.Now;
for (int counter = 0; counter <= 100000000; counter++)
{
if (strTest.Equals(string.Empty))
{
}
}
end = DateTime.Now;
ts = end - start;
Console.WriteLine("string.Equals(string.Empty) 时间消耗为 " + ts.TotalSeconds + " 秒");
//string.Length == 0
start = DateTime.Now;
for (int counter = 0; counter <= 100000000; counter++)
{
if (strTest.Length == 0)
{
}
}
end = DateTime.Now;
ts = end - start;
Console.WriteLine("string.Length == 0 时间消耗为 " + ts.TotalSeconds + " 秒");
//string.IsNullOrEmpty(string)
start = DateTime.Now;
for (int counter = 0; counter <= 100000000; counter++)
{
if (string.IsNullOrEmpty(strTest))
{
}
}
end = DateTime.Now;
ts = end - start;
Console.WriteLine("string.IsNullOrEmpty(string) 时间消耗为 " + ts.TotalSeconds + " 秒" + "/n");
}
static void Main(string[] args)
{
Console.WriteLine("=======================================");
Console.WriteLine("strTest = /"/" 的5种测试结果");
Console.WriteLine("=======================================");
Test(strTest01);
Console.WriteLine("=======================================");
Console.WriteLine("strTest = string.Emtpy 的5种测试结果");
Console.WriteLine("=======================================");
Test(strTest02);
Console.WriteLine("=======================================");
Console.WriteLine("strTest = /"0123456789/" 的5种测试结果");
Console.WriteLine("=======================================");
Test(strTest03);
Console.ReadLine(); //等待键盘的输入 作用:使屏幕暂停在此处
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有