110,561
社区成员
发帖
与我相关
我的任务
分享
unsafe static void kickoffChinese3()
{
//string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
char[] chars = content.ToCharArray();
char[] result = new char[chars.Length];
fixed (char* pChars = chars)
{
fixed (char* pResult = result)
{
char* pCurrentChars = pChars;
char* pCurrentResult = pResult;
char* pLimit = pChars + chars.Length;
while (pCurrentChars < pLimit)
{
if (*pCurrentChars < 0x4E00 || *pCurrentChars > 0x9FA5)
*pCurrentResult++ = *pCurrentChars;
pCurrentChars++;
}
*pCurrentResult = '\0';
}
}
//Console.WriteLine(new string(result));
}
regex foreach linq skep99 skep99-1 unsafe
6750 3687 5500 938 828 703
6766 3703 5437 938 828 703
6828 3797 5547 937 813 719
6796 3688 5406 891 828 703
6781 3703 5579 906 828 719
6828 3781 5734 938 828 703
6922 3719 5578 937 829 703
6734 3703 5500 938 828 719
6843 3750 5532 984 875 750
7000 3797 5562 969 828 735
6859 3672 5531 938 812 719
6875 3625 5484 922 813 734
7031 3735 5500 921 829 718
6875 3688 5500 937 813 719
6734 3672 5625 906 828 719
6781 3703 5547 906 813 719
6703 3609 5485 906 828 703
6766 3734 5625 922 828 719
6859 3719 5484 922 828 735
6750 3672 5468 922 844 703
static void Main(string[] args)
{
Console.WriteLine("regex\t\tforeach\t\tlinq\t\tskep99\t\tskep99-1");
for (int x = 0; x < 20; x++)
{
int tick = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseRegex01();
tick = Environment.TickCount - tick;
int tick1 = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseForeach01();
tick1 = Environment.TickCount - tick1;
int tick2 = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseLinq01();
tick2 = Environment.TickCount - tick2;
int tick3 = Environment.TickCount;
for (int i = 0; i < 10000; i++) kickoffChinese();
tick3 = Environment.TickCount - tick3;
int tick4 = Environment.TickCount;
for (int i = 0; i < 10000; i++) kickoffChinese1();
tick4 = Environment.TickCount - tick4;
Console.WriteLine(tick.ToString() + "\t\t" + tick1.ToString() + "\t\t" + tick2.ToString() + "\t\t" + tick3.ToString() + "\t\t" + tick4.ToString());
}
Console.ReadKey();
}
static Regex reg = new Regex(@"[\u4e00-\u9fa5]+", RegexOptions.Compiled);
static readonly string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
static StringBuilder builder = new StringBuilder(content.Length);
private static void TestChineseLinq01()
{
//string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
string result = new string(content.Where(c => ((uint)c < 0x4e00 || (uint)c > 0x9fa5)).ToArray());
//Console.WriteLine(result);
}
private static void TestChineseRegex01()
{
//string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
string result = reg.Replace(content, string.Empty);
//Console.WriteLine(result);
}
private static void TestChineseForeach01()
{
builder.Clear();
for (int i = 0; i < content.Length; i++)
{
if (content[i] < 0x4e00 || content[i] > 0x9fa5)
{
builder.Append(content[i]);
}
}
//Console.WriteLine(builder.ToString());
}
static void kickoffChinese()
{
//string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
char[] chars = content.ToCharArray();
int offset = 0;
char[] result = new char[chars.Length];
for (int i = 0; i < chars.Length; i++)
{
if (chars[i] < 0x4E00 || chars[i] > 0x9FA5)
{
result[offset] = chars[i];
offset++;
}
}
char[] dest = new char[offset];
Array.Copy(result, dest, offset);
//Console.WriteLine(new string(dest));
}
static void kickoffChinese1()
{
//string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
char[] chars = content.ToCharArray();
int offset = 0;
char[] result = new char[chars.Length];
for (int i = 0; i < chars.Length; i++)
{
if (chars[i] < 0x4E00 || chars[i] > 0x9FA5)
{
result[offset] = chars[i];
offset++;
}
}
//char[] dest = new char[offset];
//Array.Copy(result, dest, offset);
result[offset + 1] = '\0';
//Console.WriteLine(new string(result));
//Console.WriteLine(new string(dest));
}
regex foreach linq skep99 skep99-1
130 60 241 60 40
180 50 211 40 40
120 60 170 40 40
130 61 170 50 30
120 60 170 40 41
130 50 180 50 30
130 60 181 40 40
130 60 170 50 30
131 50 180 40 40
130 110 241 60 40
150 60 190 51 50
130 60 170 40 40
120 61 170 50 30
130 60 170 40 41
120 60 170 50 40
130 60 171 50 30
120 60 170 50 30
131 60 180 40 40
120 60 171 40 40
120 60 180 40 40
static void Main(string[] args)
{
Console.WriteLine("regex\t\tforeach\t\tlinq\t\tkickoffChinese");
for (int x = 0; x < 20; x++)
{
int tick = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseRegex01();
tick = Environment.TickCount - tick;
int tick1 = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseForeach01();
tick1 = Environment.TickCount - tick1;
int tick2 = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseLinq01();
tick2 = Environment.TickCount - tick2;
int tick3 = Environment.TickCount;
for (int i = 0; i < 10000; i++) kickoffChinese();
tick3 = Environment.TickCount - tick3;
Console.WriteLine(tick.ToString() + "\t\t" + tick1.ToString() + "\t\t" + tick2.ToString() + "\t\t" + tick3.ToString());
}
Console.ReadKey();
}
static Regex reg = new Regex(@"[\u4e00-\u9fa5]+", RegexOptions.Compiled);
static string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
static StringBuilder builder = new StringBuilder(content.Length);
private static void TestChineseLinq01()
{
//string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
string result = new string(content.Where(c => ((uint)c < 0x4e00 || (uint)c > 0x9fa5)).ToArray());
//Console.WriteLine(result);
}
private static void TestChineseRegex01()
{
//string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
string result = reg.Replace(content, string.Empty);
//Console.WriteLine(result);
}
private static void TestChineseForeach01()
{
builder.Clear();
for (int i = 0; i < content.Length; i++)
{
if (content[i] < 0x4e00 || content[i] > 0x9fa5)
{
builder.Append(content[i]);
}
}
//Console.WriteLine(builder.ToString());
}
static void kickoffChinese()
{
//string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
char[] chars = content.ToCharArray();
int offset = 0;
char[] result = new char[chars.Length];
for (int i = 0; i < chars.Length; i++)
{
if (chars[i] < 0x4E00 || chars[i] > 0x9FA5)
{
result[offset] = chars[i];
offset++;
}
}
char[] dest = new char[offset];
Array.Copy(result, dest, offset);
//Console.WriteLine(new string(dest));
}
regex foreach linq kickoffChinese
140 60 261 40
130 60 170 50
181 70 190 50
120 60 170 41
130 60 170 40
130 60 171 50
120 60 170 40
130 61 170 40
130 60 160 50
121 70 170 50
120 70 241 60
170 70 180 50
151 60 170 50
120 60 171 40
130 60 160 50
130 60 161 50
120 60 170 40
120 61 170 40
130 60 160 50
121 60 170 40
REGEX linq kickoffChinese
156 32 15
157 47 15
172 31 16
156 47 16
140 47 16
156 31 16
156 47 16
156 47 15
141 47 16
140 47 16
156 31 16
156 47 16
140 47 16
140 47 16
140 47 16
156 47 16
140 47 16
140 47 16
141 46 16
156 32 15
static void Main(string[] args)
{
Console.WriteLine("regex" + "\t\t" + "foreach" + "\t\t" + "linq");
for (int x = 0; x < 20; x++)
{
int tick = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseRegex01();
tick = Environment.TickCount - tick;
int tick1 = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseForeach01();
tick1 = Environment.TickCount - tick1;
int tick2 = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseLinq01();
tick2 = Environment.TickCount - tick2;
Console.WriteLine(tick.ToString() + "\t\t" + tick1.ToString() + "\t\t" + tick2.ToString());
}
Console.ReadKey();
}
private static void TestChineseLinq01()
{
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
string result = new string(content.Where(c => ((uint)c < 0x4e00 || (uint)c > 0x9fa5)).ToArray());
//Console.WriteLine(result);
}
private static void TestChineseRegex01()
{
Regex reg = new Regex(@"[\u4e00-\u9fa5]+");
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
string result = reg.Replace(content, "");
//Console.WriteLine(result);
}
private static void TestChineseForeach01()
{
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
StringBuilder builder = new StringBuilder(content.Length);
for (int i = 0; i < content.Length; i++)
{
int n = char.ConvertToUtf32(content, i);
if (n < 0x4e00 || n > 0x9fa5)
{
builder.Append(content[i]);
}
}
//Console.WriteLine(builder.ToString());
}
regex foreach linq
203 47 94
171 31 94
156 47 78
171 47 78
156 47 62
172 31 78
156 47 78
156 47 78
156 47 78
156 31 78
218 47 78
172 31 78
171 47 78
156 47 78
172 46 78
156 47 78
172 31 78
156 47 78
171 32 78
171 31 78
void kickoffChinese()
{
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
char[] chars = content.ToCharArray();
int offset = 0;
char[] result = new char[chars.Length];
for (int i = 0; i < chars.Length; i++)
{
if (chars[i] < 0x4E00 || chars[i] > 0x9FA5)
{
result[offset] = chars[i];
offset++;
}
}
char[] dest=new char[offset];
Array.Copy(result, dest, offset);
//Console.WriteLine(new string(dest));
}
static void Main(string[] args)
{
for (int x = 0; x < 20; x++)
{
int tick = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseRegex01();
tick = Environment.TickCount - tick;
int tick1 = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseRegex01();
tick1 = Environment.TickCount - tick1;
int tick2 = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseLinq01();
tick2 = Environment.TickCount - tick2;
Console.WriteLine(tick.ToString() + "\t" + tick1.ToString() + "\t" + tick2.ToString());
}
Console.ReadKey();
}
private static void TestChineseLinq01()
{
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
string result = new string(content.Where(c => ((uint)c < 0x4e00 || (uint)c > 0x9fa5)).ToArray());
//Console.WriteLine(result);
}
private static void TestChineseRegex01()
{
Regex reg = new Regex(@"[\u4e00-\u9fa5]+");
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
string result = reg.Replace(content, "");
//Console.WriteLine(result);
}
regex foreach linq
203 171 94
156 172 78
171 172 78
171 156 78
172 172 78
171 156 94
156 171 78
156 156 94
156 172 78
156 171 78
172 156 78
171 188 93
156 156 94
156 187 140
156 172 94
156 171 78
172 171 78
156 172 78
172 156 78
171 156 78
static void Main(string[] args)
{
for (int x = 0; x < 20; x++)
{
int tick = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseRegex01();
tick = Environment.TickCount - tick;
int tick1 = Environment.TickCount;
for (int i = 0; i < 10000; i++) TestChineseRegex01();
tick1 = Environment.TickCount - tick1;
Console.WriteLine(tick.ToString() + "," + tick1.ToString());
}
Console.ReadKey();
}
private static void TestChineseRegex01()
{
Regex reg = new Regex(@"[\u4e00-\u9fa5]+");
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
string result = reg.Replace(content, "");
//Console.WriteLine(result);
}
private static void TestChinese()
{
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
StringBuilder builder = new StringBuilder(content.Length);
for (int i = 0; i < content.Length; i++)
{
int n = char.ConvertToUtf32(content, i);
if (n < 0x4e00 || n > 0x9fa5)
{
builder.Append(content[i]);
}
}
//Console.WriteLine(builder.ToString());
}