﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Simple is beautifull-最新评论</title><link>http://www.cppblog.com/reginfo/CommentsRSS.aspx</link><description>还需要副标题吗？</description><language>zh-cn</language><pubDate>Sat, 01 Apr 2006 14:10:00 GMT</pubDate><lastBuildDate>Sat, 01 Apr 2006 14:10:00 GMT</lastBuildDate><generator>cnblogs</generator><item><title>re: 为什么Python的性能比较好呢？</title><link>http://www.cppblog.com/reginfo/archive/2006/04/01/4855.html#4889</link><dc:creator>christanxw</dc:creator><author>christanxw</author><pubDate>Sat, 01 Apr 2006 14:10:00 GMT</pubDate><guid>http://www.cppblog.com/reginfo/archive/2006/04/01/4855.html#4889</guid><description><![CDATA[#include &lt;windows.h&gt;<br>#include &lt;cstdio&gt;<br>#include &lt;iostream&gt;<br><br>unsigned long cryptTable[0x500];<br>const int HASH	= 0;<br>const int HASH_A  = 1;<br>const int HASH_B  = 2;<br><br>void InitCryptTable()<br>{ <br>	unsigned long seed = 0x00100001, index1 = 0, index2 = 0, i;<br>	for(index1 = 0; index1 &lt; 0x100; index1++)<br>	{ <br>		for(index2 = index1, i = 0; i &lt; 5; i++, index2 += 0x100)<br>		{ <br>			unsigned long temp1, temp2;<br>			seed = (seed * 125 + 3) % 0x2AAAAB;<br>			temp1 = (seed &amp; 0xFFFF) &lt;&lt; 0x10;<br>			seed = (seed * 125 + 3) % 0x2AAAAB;<br>			temp2 = (seed &amp; 0xFFFF);<br>			cryptTable[index2] = (temp1 | temp2); <br>		} <br>	} <br>}<br><br>unsigned long Hash(char *pStr, unsigned long dwHashType)<br>{ <br>	unsigned char *key = (unsigned char *)pStr;<br>	unsigned long seed1 = 0x7FED7FED, seed2 = 0xEEEEEEEE;<br>	int ch;<br><br>	while(*key != 0)<br>	{ <br>		ch = toupper(*key++);<br><br>		seed1 = cryptTable[(dwHashType &lt;&lt; 8) + ch] ^ (seed1 + seed2);<br>		seed2 = ch + seed1 + seed2 + (seed2 &lt;&lt; 5) + 3; <br>	}<br>	return seed1; <br>} <br><br>struct HashItem<br>{<br>	unsigned long	m_nHashKeyA;<br>	unsigned long	m_nHashKeyB;<br>	bool		m_bExist;<br>};<br><br>int main()<br>{	<br>	__int64 t1, t2; <br>	GetSystemTimeAsFileTime( (LPFILETIME)&amp;t1 ); <br><br>	InitCryptTable();<br>	FILE* fread = fopen(&quot;c:\\email.txt&quot;,&quot;r&quot;);<br>	FILE* fwrite = fopen(&quot;c:\\emailnew.txt&quot;,&quot;w+&quot;);<br><br>	HashItem *hashTable = new HashItem[780000];<br><br>	char line[256] = &quot;&quot;;<br>	fgets(line,255,fread);<br>	while(!feof(fread))<br>	{<br> 		int nStart = Hash(line,HASH) % 780000;<br>		int nPos = nStart;<br>		if(!(hashTable[nPos].m_bExist<br>			&amp;&amp; hashTable[nPos].m_nHashKeyA ==Hash(line,HASH_A)<br>			&amp;&amp; hashTable[nPos].m_nHashKeyB == Hash(line,HASH_B)))<br>		{<br>			hashTable[nPos].m_nHashKeyA = Hash(line,HASH_A);<br>			hashTable[nPos].m_nHashKeyB = Hash(line,HASH_B);<br>			hashTable[nPos].m_bExist = true;<br>			fprintf(fwrite,&quot;%s&quot;,line);<br>		}<br>		<br>		fgets(line,255,fread);<br>	}<br><br>	GetSystemTimeAsFileTime( (LPFILETIME)&amp;t2 ); <br>	printf( &quot;经过了%I64d.%04I64d毫秒\n&quot;, (t2-t1)/10000, (t2-t1)%10000 ); <br>	fclose(fread); <br>	fclose(fwrite); <br>	delete [] hashTable; <br><br>	std::cin.get();<br>}<br><br>耗时343毫秒。很不错了。呵呵。Ptyong也是C写出来的，C/C++效率是完全可以比Pyton更快的，就看怎么实现算法了。在总多的脚本语言中Python是比较慢的一个了。<img src ="http://www.cppblog.com/reginfo/aggbug/4889.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/reginfo/" target="_blank">christanxw</a> 2006-04-01 22:10 <a href="http://www.cppblog.com/reginfo/archive/2006/04/01/4855.html#4889#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 为什么Python的性能比较好呢？</title><link>http://www.cppblog.com/reginfo/archive/2006/03/31/4855.html#4861</link><dc:creator>铏瓙</dc:creator><author>铏瓙</author><pubDate>Fri, 31 Mar 2006 10:24:00 GMT</pubDate><guid>http://www.cppblog.com/reginfo/archive/2006/03/31/4855.html#4861</guid><description><![CDATA[2. 参看Python代码实现的实现<br>#include &lt;cstdio&gt; <br><br>// code by 李嘉<br>// 禁止任何商业目的的转载<br>// 不对因使用代码产生任何后果负任何责任<br>// 转载请保留所有声明<br><br>#include &lt;windows.h&gt;  <br>using namespace std; <br><br><br>#define c_mul(a, b) (a * b &amp; 0xFFFFFFFF) <br><br>size_t python_hash(const char * str) <br>{ <br>	size_t value = str[0] &lt;&lt; 7; <br>	size_t len = 0; <br>	while(*str != 0) <br>	{ <br>		value = c_mul(1000003, value) ^ *str++; <br>		len++; <br>	} <br><br>	value = value ^ len; <br>	if (value == (size_t)-1) <br>	value = (size_t)-2; <br>	return value; <br>} <br><br>size_t hash(const char * str, size_t seed = 1) <br>{ <br>	size_t h = 0, g;  <br>	size_t len = 0; <br>	while (*str)<br>	{  <br>		h = (h &lt;&lt; 4) + *str++;  <br>		if ((g = (h &amp; 0xF0000000))) {  <br>			h = h ^ (g &gt;&gt; 24);  <br>			h = h ^ g;  <br>			h = h ^ seed; <br>		}  <br>		len++; <br>	}  <br>	return h;  <br>} <br><br><br>#define MAX_TABLE_SIZE (780000) <br>#define MAX_CONFI 9 <br><br>struct hash_item <br>{ <br>	size_t items[MAX_CONFI]; <br>	size_t item_count; <br>	hash_item() <br>	{ <br>		item_count = 0; <br>	} <br>	bool check_has(const char * str) <br>	{ <br>		size_t key = hash(str); <br>		for(size_t i = 0; i &lt; item_count; i++) <br>		{ <br>			if (items[i] == key) <br>			return true; <br>		} <br>		items[item_count++] = key; <br>		return false; <br>	} <br><br>}; <br><br><br>int main( void ) <br>{ <br>	__int64 t1, t2; <br>	GetSystemTimeAsFileTime( (LPFILETIME)&amp;t1 ); <br>	FILE * fin = fopen(&quot;email.txt&quot;, &quot;r&quot;); <br>	FILE * fout = fopen(&quot;email_new_my.txt&quot;, &quot;w+&quot;); <br><br>	size_t hash_key_a = 0; <br>	size_t hash_key_b = 0; <br>	size_t pos_x = 0; <br>	size_t pos_y = 0; <br>	const char * buffer = NULL; <br>	char line[255]; <br>	fgets(line, 255, fin); <br>	hash_item * table = new hash_item[MAX_TABLE_SIZE]; <br>	while(!feof(fin)) <br>	{ <br>		buffer = line; <br>		hash_key_a = python_hash(buffer); <br>		pos_x = hash_key_a % MAX_TABLE_SIZE; <br>		if (!table[pos_x].check_has(buffer)) <br>			fprintf(fout, &quot;%s&quot;, buffer); <br>	<br>		fgets(line, 255, fin); <br>	} <br>	GetSystemTimeAsFileTime( (LPFILETIME)&amp;t2 ); <br>	printf( &quot;经过了%I64d.%04I64d毫秒\n&quot;, (t2-t1)/10000, (t2-t1)%10000 ); <br>	fclose(fin); <br>	fclose(fout); <br>	delete [] table; <br>} <br><br>from link：<br><a target="_new" href="http://blog.csdn.net/imjj/archive/2006/03/31/645163.aspx?Pending=true">http://blog.csdn.net/imjj/archive/2006/03/31/645163.aspx?Pending=true</a><img src ="http://www.cppblog.com/reginfo/aggbug/4861.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/reginfo/" target="_blank">铏瓙</a> 2006-03-31 18:24 <a href="http://www.cppblog.com/reginfo/archive/2006/03/31/4855.html#4861#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 为什么Python的性能比较好呢？</title><link>http://www.cppblog.com/reginfo/archive/2006/03/31/4855.html#4860</link><dc:creator>虫子</dc:creator><author>虫子</author><pubDate>Fri, 31 Mar 2006 10:23:00 GMT</pubDate><guid>http://www.cppblog.com/reginfo/archive/2006/03/31/4855.html#4860</guid><description><![CDATA[为了方便日后查看（怕那些链接无效了），特意把一些其他实现的代码摘录下来：<br>====================================================1.Python的原始实现：<br>#remove duplicated email address from file<br>import datetime<br>if __name__ == &quot;__main__&quot;:<br> t = datetime.datetime(2000,1,1)<br> print str(t.today())<br> hashtable = {}<br> f = file(&quot;email.txt&quot;,&quot;r&quot;)<br> f2 = file(&quot;email_new.txt&quot;,&quot;w&quot;)<br> line = f.readline();<br> while len(line)&gt;0:<br>  if not hashtable.has_key(line): <br>   hashtable[line] = 1<br>   f2.write(line)<br>  line = f.readline();<br> f.close()<br> f2.close()<br> t2 = datetime.datetime(2000,1,1)<br> print str(t2.today())<br><br>from link：<br><a target="_new" href="http://blog.vckbase.com/jzhang/archive/2006/03/28/18807.html">http://blog.vckbase.com/jzhang/archive/2006/03/28/18807.html</a><br>====================================================<br><img src ="http://www.cppblog.com/reginfo/aggbug/4860.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/reginfo/" target="_blank">虫子</a> 2006-03-31 18:23 <a href="http://www.cppblog.com/reginfo/archive/2006/03/31/4855.html#4860#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: boost::thread 中使用类成员作为线程入口</title><link>http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3177</link><dc:creator>音乐虫子</dc:creator><author>音乐虫子</author><pubDate>Fri, 10 Feb 2006 08:10:00 GMT</pubDate><guid>http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3177</guid><description><![CDATA[嘻嘻，初来乍到，不懂规矩，请莫见怪：）<br><img src ="http://www.cppblog.com/reginfo/aggbug/3177.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/reginfo/" target="_blank">音乐虫子</a> 2006-02-10 16:10 <a href="http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3177#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: boost::thread 中使用类成员作为线程入口</title><link>http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3173</link><dc:creator>有啥都往首页放  </dc:creator><author>有啥都往首页放  </author><pubDate>Fri, 10 Feb 2006 07:18:00 GMT</pubDate><guid>http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3173</guid><description><![CDATA[而且涉及boost库，又有技术含量。<img src ="http://www.cppblog.com/reginfo/aggbug/3173.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/reginfo/" target="_blank">有啥都往首页放  </a> 2006-02-10 15:18 <a href="http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3173#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: boost::thread 中使用类成员作为线程入口</title><link>http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3168</link><dc:creator>有啥都往首页放</dc:creator><author>有啥都往首页放</author><pubDate>Fri, 10 Feb 2006 04:51:00 GMT</pubDate><guid>http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3168</guid><description><![CDATA[不错，文章够原创的。<img src ="http://www.cppblog.com/reginfo/aggbug/3168.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/reginfo/" target="_blank">有啥都往首页放</a> 2006-02-10 12:51 <a href="http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3168#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: boost::thread 中使用类成员作为线程入口</title><link>http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3160</link><dc:creator>音乐虫子</dc:creator><author>音乐虫子</author><pubDate>Fri, 10 Feb 2006 02:07:00 GMT</pubDate><guid>http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3160</guid><description><![CDATA[refer www.boost.org please:)<br><img src ="http://www.cppblog.com/reginfo/aggbug/3160.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/reginfo/" target="_blank">音乐虫子</a> 2006-02-10 10:07 <a href="http://www.cppblog.com/reginfo/archive/2006/02/10/3152.html#3160#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: boost::thread 中使用类成员作为线程入口</title><link>http://www.cppblog.com/reginfo/archive/2006/02/09/3152.html#3154</link><dc:creator>思春贴调查员(Khan)</dc:creator><author>思春贴调查员(Khan)</author><pubDate>Thu, 09 Feb 2006 15:30:00 GMT</pubDate><guid>http://www.cppblog.com/reginfo/archive/2006/02/09/3152.html#3154</guid><description><![CDATA[没有看明白<br>boost是什么啊<img src ="http://www.cppblog.com/reginfo/aggbug/3154.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/reginfo/" target="_blank">思春贴调查员(Khan)</a> 2006-02-09 23:30 <a href="http://www.cppblog.com/reginfo/archive/2006/02/09/3152.html#3154#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>