其他部门人员用C++采集到的数据记录格式如下:
数据库字段名:(varbinary)(8000)
0x61313534300000000000000000000000
61313534310000000100010001000100
61313534300000000000000000000000
61313534310000000100010001000100
横向有500个信息;用C#解析后单个数据如下:a1540,0,0,0,0
按每天900条数据计算,C#共要循环900*500次。
我这边用asp.net统计一天的数据,服务器会计算35秒,再跟其它数据信息汇总共用时46秒,无法接受。。
但C++那边将数据取出之后直接操作内存,一个指向每行的数据就统计出来了,因此只需缓缓900行,用时3.2秒。
C++的代码不贴了,下面贴出C#代码,望大侠给出解决办法.
SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();
while (mySqlDataReader.Read())
{
System.Data.SqlTypes.SqlBinary mySqlBinary = mySqlDataReader.GetSqlBinary(0);
int nArrayLen = mySqlBinary.Length / 16;
for (int nArrayIndex = 0; nArrayIndex < nArrayLen; nArrayIndex++)
{
byte[] bySubSite = new byte[8];
byte[] byIP = new byte[2];
byte[] byWindow = new byte[2];
byte[] byReach = new byte[2];
byte[] byClick = new byte[2];
for (int i = 0; i < 8; i++)
{
bySubSite[i] = mySqlBinary.Value[nArrayIndex * 16 + i];
}
for (int i = 0; i < 2; i++)
{
byIP[i] = mySqlBinary.Value[nArrayIndex * 16 + 8 + i];
}
for (int i = 0; i < 2; i++)
{
byWindow[i] = mySqlBinary.Value[nArrayIndex * 16 + 10 + i];
}
for (int i = 0; i < 2; i++)
{
byReach[i] = mySqlBinary.Value[nArrayIndex * 16 + 12 + i];
}
for (int i = 0; i < 2; i++)
{
byClick[i] = mySqlBinary.Value[nArrayIndex * 16 + 14 + i];
}
string strValue = Encoding.Default.GetString(bySubSite);
int nIPCount = System.BitConverter.ToInt16(byIP, 0);
int nWindowCount = System.BitConverter.ToInt16(byWindow, 0);
int nReachCount = System.BitConverter.ToInt16(byReach, 0);
int nClickCount = System.BitConverter.ToInt16(byClick, 0);
string subid = strValue.Replace("\0", "");
if (ht.ContainsKey(subid))
{ string[] iii = ht[subid].ToString().Split('_'); int ipnum = int.Parse(iii[0]) + nIPCount; int wnum = int.Parse(iii[1]) + nWindowCount; int rnum = int.Parse(iii[2]) + nReachCount; int cnum = int.Parse(iii[3]) + nClickCount; ht[subid] = ipnum.ToString() + "_" + wnum.ToString() + "_" + rnum.ToString() + "_" +
cnum.ToString() + "_" + arrPromocodeMemberReg.Length + "_" + arrPromocodeMemberlogin.Length + "_" +
arrPromocodeMemberpaynum.Length;
}
else
{
string key = subid; string value = nIPCount.ToString() + "_" + nWindowCount.ToString() + "_" +
nReachCount.ToString() + "_" + nClickCount.ToString() + "_" + arrPromocodeMemberReg.Length + "_" +
arrPromocodeMemberlogin.Length + "_" + arrPromocodeMemberpaynum.Length;
ht.Add(key, value);
}
}
}
mySqlDataReader.Close();
mySqlDataReader.Dispose();
mySqlConnection.Close();
数据库字段名:(varbinary)(8000)
0x61313534300000000000000000000000
61313534310000000100010001000100
61313534300000000000000000000000
61313534310000000100010001000100
横向有500个信息;用C#解析后单个数据如下:a1540,0,0,0,0
按每天900条数据计算,C#共要循环900*500次。
我这边用asp.net统计一天的数据,服务器会计算35秒,再跟其它数据信息汇总共用时46秒,无法接受。。
但C++那边将数据取出之后直接操作内存,一个指向每行的数据就统计出来了,因此只需缓缓900行,用时3.2秒。
C++的代码不贴了,下面贴出C#代码,望大侠给出解决办法.
SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();
while (mySqlDataReader.Read())
{
System.Data.SqlTypes.SqlBinary mySqlBinary = mySqlDataReader.GetSqlBinary(0);
int nArrayLen = mySqlBinary.Length / 16;
for (int nArrayIndex = 0; nArrayIndex < nArrayLen; nArrayIndex++)
{
byte[] bySubSite = new byte[8];
byte[] byIP = new byte[2];
byte[] byWindow = new byte[2];
byte[] byReach = new byte[2];
byte[] byClick = new byte[2];
for (int i = 0; i < 8; i++)
{
bySubSite[i] = mySqlBinary.Value[nArrayIndex * 16 + i];
}
for (int i = 0; i < 2; i++)
{
byIP[i] = mySqlBinary.Value[nArrayIndex * 16 + 8 + i];
}
for (int i = 0; i < 2; i++)
{
byWindow[i] = mySqlBinary.Value[nArrayIndex * 16 + 10 + i];
}
for (int i = 0; i < 2; i++)
{
byReach[i] = mySqlBinary.Value[nArrayIndex * 16 + 12 + i];
}
for (int i = 0; i < 2; i++)
{
byClick[i] = mySqlBinary.Value[nArrayIndex * 16 + 14 + i];
}
string strValue = Encoding.Default.GetString(bySubSite);
int nIPCount = System.BitConverter.ToInt16(byIP, 0);
int nWindowCount = System.BitConverter.ToInt16(byWindow, 0);
int nReachCount = System.BitConverter.ToInt16(byReach, 0);
int nClickCount = System.BitConverter.ToInt16(byClick, 0);
string subid = strValue.Replace("\0", "");
if (ht.ContainsKey(subid))
{ string[] iii = ht[subid].ToString().Split('_'); int ipnum = int.Parse(iii[0]) + nIPCount; int wnum = int.Parse(iii[1]) + nWindowCount; int rnum = int.Parse(iii[2]) + nReachCount; int cnum = int.Parse(iii[3]) + nClickCount; ht[subid] = ipnum.ToString() + "_" + wnum.ToString() + "_" + rnum.ToString() + "_" +
cnum.ToString() + "_" + arrPromocodeMemberReg.Length + "_" + arrPromocodeMemberlogin.Length + "_" +
arrPromocodeMemberpaynum.Length;
}
else
{
string key = subid; string value = nIPCount.ToString() + "_" + nWindowCount.ToString() + "_" +
nReachCount.ToString() + "_" + nClickCount.ToString() + "_" + arrPromocodeMemberReg.Length + "_" +
arrPromocodeMemberlogin.Length + "_" + arrPromocodeMemberpaynum.Length;
ht.Add(key, value);
}
}
}
mySqlDataReader.Close();
mySqlDataReader.Dispose();
mySqlConnection.Close();
解决方案 »
- 请教下页面后退时如何使JS提示框不弹出?
- '编码问题
- 自己写的一个DBHELPER期待高手帮忙看一下,有什么不好的地方!
- 小和尚不明白呀,大散分~!~!~!~!~!~!~
- 如何使文本框中只能输入数字,不能输入其他字符或汉字?如保判断网址格式(正则表达式)?急!!!
- 找不到文件或程序集名称“System”,或找不到它的一个依赖项
- 请教:如何在web服务器向另一台有完全控制权限的机上读写文件?
- 基础题,马上给分!
- msgbox本地成功,远程服务器失败?结贴率100%
- 框架中的子窗口能否接受传给它父窗口的数据?
- 请问一下关于一IIS问题
- asp.net MVC 如何结合jquery开发?求最简单的例子
byte[] bySubSite = new byte[8];
byte[] byIP = new byte[2];
byte[] byWindow = new byte[2];
byte[] byReach = new byte[2];
byte[] byClick = new byte[2];
都可以重用的。
for (int i = 0; i < 8; i++)
{
bySubSite[i] = mySqlBinary.Value[nArrayIndex * 16 + i];
}
for (int i = 0; i < 2; i++)
{
byIP[i] = mySqlBinary.Value[nArrayIndex * 16 + 8 + i];
}
for (int i = 0; i < 2; i++)
{
byWindow[i] = mySqlBinary.Value[nArrayIndex * 16 + 10 + i];
}
for (int i = 0; i < 2; i++)
{
byReach[i] = mySqlBinary.Value[nArrayIndex * 16 + 12 + i];
}
for (int i = 0; i < 2; i++)
{
byClick[i] = mySqlBinary.Value[nArrayIndex * 16 + 14 + i];
}这些用Array.Copy会死啊。
string value = nIPCount.ToString() + "_" + nWindowCount.ToString() + "_" +
nReachCount.ToString() + "_" + nClickCount.ToString() + "_" + arrPromocodeMemberReg.Length + "_" +
arrPromocodeMemberlogin.Length + "_" + arrPromocodeMemberpaynum.Length;
用StringBuilder拼接会死啊,用string.Format会死啊不会高效的用C#就别嫌C#比C++慢。
按照这样我也能写出比Java还慢的汇编。