**using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpPcap;
using PacketDotNet;
using SharpPcap.LibPcap;
using System.Threading;
namespace ConsoleApplication3
{
class Program
{
public static void OrderByEx1()
{
Pet[] pets = { new Pet { Name=“Barley”, Age=8 },
new Pet { Name=“Boots”, Age=4 },
new Pet { Name=“Bjs”, Age=4 },
new Pet { Name=“Hui”, Age=1},
new Pet { Name=“Whiskers”, Age=1 } };
IEnumerable query = pets.OrderBy(pet => pet.Age);
foreach (Pet pet in query)
Console.WriteLine("{0} - {1}", pet.Name, pet.Age);
}
static void Main0(string[] args)
{
TestClass tec = new TestClass();
//tec.MyDict.OrderBy
foreach (var it in tec.MyDict)
{
Console.WriteLine(“key is :{0} val is:{1}”,it.Key,it.Value);
}
OrderByEx1();
//KeyValuePair a;
//a.Key
//IEnumerable>
var querte = tec.MyDict.OrderBy(x=>x.Key);
foreach (var it in querte)
{
Console.WriteLine("key is :{0} val is:{1}", it.Key, it.Value);
}
byte [] data0=new byte[100];
byte[] data1 = BitConverter.GetBytes('a');
data0[0] = data1[0];
data0[1] = data1[1];
byte[] data2 = BitConverter.GetBytes('阿');
Console.ReadLine();
}
public static byte[] Str2ByteAry(string str)
{
char[] tmpcary = str.ToCharArray();
List tmpsry = new List();
var tmpsry2 = new Queue();
foreach (var item in tmpcary)
{
tmpsry.AddRange(BitConverter.GetBytes(item));
}
return tmpsry.ToArray();
// return new byte[]{0x00};
}
}
class Pet
{
public string Name;
public int Age;
}
}
class Class1
{
[System.Runtime.InteropServices.DllImport ("Kernel32.dll")]
static extern bool QueryPerformanceCounter(ref long count);
[System.Runtime.InteropServices.DllImport ("Kernel32.dll")]
static extern bool QueryPerformanceFrequency(ref long count);
private static bool runflag = true;
private static List rawcaplist = new List();
[STAThread]
static void Main(string[] args)
{
long count = 0;
long count1 = 0;
long freq = 0;
double result = 0;
byte[] nbyteary={0};
Thread backgrdthd = new Thread(backthd);
CaptureFileWriterDevice offlinefile = new CaptureFileWriterDevice(@"E:\bjzx\抓包数据\1309045writeaxis70sec.pcap");
ICaptureDevice offlinedevice = new CaptureFileReaderDevice(@"E:\bjzx\抓包数据\1309045axis70sec.pcap");
//ICaptureDevice offlinedevice = new CaptureFileReaderDevice(@"E:\bjzx\抓包数据\pc5net.pcap");
QueryPerformanceFrequency(ref freq);
QueryPerformanceCounter(ref count);
//开始的时候没有这层循环,所得数据浮动很大,添加这层循环来使得结果更加平均
for (int i=0; i<500; i++)
{
//需要测试的模块
nbyteary = ConsoleApplication3.Program.Str2ByteAry("123");
}
QueryPerformanceCounter(ref count1);
count = count1 - count;
result = (double)(count) / (double)freq;
Console.WriteLine("计算耗时: {0} 秒", result);
QueryPerformanceCounter(ref count);
int tempvar = 0;
//开始的时候没有这层循环,所得数据浮动很大,添加这层循环来使得结果更加平均
for (int i = 0; i < 500; i++)
{
//需要测试的模块
Console.WriteLine(BitConverter.ToString(nbyteary));
//Console.WriteLine("ok");
tempvar = i * 4 + i * i;
}
QueryPerformanceCounter(ref count1);
count = count1 - count;
result = (double)(count) / (double)freq;
Console.WriteLine("console耗时: {0} 秒", result);
Console.WriteLine(BitConverter.ToString(ConsoleApplication3.Program.Str2ByteAry("123")));
//计时读取pcap文件
QueryPerformanceCounter(ref count);
RawCapture packetn;
long ict=0;
while (( packetn=offlinedevice.GetNextPacket())!=null)
{
ict++;
// var paeth = (EthernetPacket)PacketDotNet.Packet.ParsePacket(packetn.LinkLayerType, packetn.Data);
//offlinefile.Write(packetn);
//var timet = packetn.Timeval;
rawcaplist.Add(packetn);
if (ict%1000000==0)
{
// rawcaplist.Clear();
Console.WriteLine("1 million");
}
// Console.WriteLine(paeth.ToString());
}
QueryPerformanceCounter(ref count1);
count = count1 - count;
result = (double)(count) / (double)freq;
Console.WriteLine(ict);
Console.WriteLine("读取耗时: {0} 秒", result);
ict = 0;
rawcaplist.Reverse();
QueryPerformanceCounter(ref count);
foreach (var pkt in rawcaplist)
{
ict++;
offlinefile.Write(pkt);
}
QueryPerformanceCounter(ref count1);
count = count1 - count;
result = (double)(count) / (double)freq;
Console.WriteLine(ict);
Console.WriteLine("写入耗时: {0} 秒", result);
Console.WriteLine(BitConverter.ToString(ConsoleApplication3.Program.Str2ByteAry("123")));
Console.ReadLine();
}
private static void backthd()
{
while (runflag)
{
if (rawcaplist!=null)
{
}
}
return;
}
}
————————————————
版权声明:本文为CSDN博主「zhiying678」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhiying678/article/details/11938993**