代码PK比赛--求高手去PK掉梁总

寻找自我 2012-09-04 03:33:38
今天梁斌在微博上面搞了一个比赛,很多人表示很有兴趣。
我看了一下,题目在这里。http://coderpk.com/

大家讨论讨论题目。
...全文
322 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
IVERS0N 2012-09-06
  • 打赏
  • 举报
回复
赵老师最喜欢这种比赛了
寻找自我 2012-09-05
  • 打赏
  • 举报
回复

好代码一起分享
[Quote=引用 6 楼 的回复:]

2)凡是性能好于我的代码,都需要开放源代码,包括我自己的代码

拒绝参加
[/Quote]
图灵狗 2012-09-05
  • 打赏
  • 举报
回复
很有趣!
dahaiI0 2012-09-05
  • 打赏
  • 举报
回复
因此你们要牛逼,就来翻我的底牌吧
-------------------------
又不是美女的裙子,不会也没兴趣翻。
ohayou 2012-09-05
  • 打赏
  • 举报
回复
2)凡是性能好于我的代码,都需要开放源代码,包括我自己的代码

拒绝参加
  • 打赏
  • 举报
回复
翅膀又硬了 2012-09-05
  • 打赏
  • 举报
回复
为什么要用那么多线程?难道你的电脑很多核?
寻找自我 2012-09-04
  • 打赏
  • 举报
回复
游戏规则:

10亿数据(每个数据看作一个同志),1个队列,10个线程push,10个线程pop,走完一遍,考察总耗时,耗时最短的获胜。我的代码在我自己机器10亿数据排队进出,耗时1分28秒 我的代码在我自己机器上耗时1分28秒,10亿数据排队进出。

1)为防止作弊,每次入队的时候,我们采用当前时间戳入队,出队的时候,比较时间戳,不要太长,否则有过分批处理嫌疑。

2)凡是性能好于我的代码,都需要开放源代码,包括我自己的代码

3)万一,没有人的代码能跑过我的,我的代码将持续闭源,因此你们要牛逼,就来翻我的底牌吧

4) 有自信战胜我的同志,把可执行程序,发到我的邮箱jackliang@vip.sina.com,最后统一在我的程序上跑结果,进行比较

5) 赞助商赞助超过2000元的,可以拿到我的代码
寻找自我 2012-09-04
  • 打赏
  • 举报
回复
程序框架

#include <stdio.h>
#include <pthread.h>
#include <string.h>
#include <stdlib.h>
#include "time_count.h"
#include "stdint.h"

const int count_per_thread_push = 100000000;

const float CPU_MHZ = 1596; //use cat /proc/cpuinfo get the value
const float CPU_tick_count_per_second = CPU_MHZ*1000*1000;

struct lock_free_queue //我把实现部分去掉了,框架供参考,其中打印部分帮助调试,确定延迟。正式比拼可以注释掉。
{
void push(unsigned long long pop_time)
{
};
bool pop()
{
/*if(now%(1000000) == 0)
{
printf("task get:%u,task write:%u,latency:%lf\n",m_head[now],rdtsc(),(rdtsc()-m_head[now])/CPU_tick_count_per_second);
}*/
};
lock_free_queue()
{
};
~lock_free_queue()
{

}
};


void* pop(void* queue)
{
lock_free_queue* lfq = (lock_free_queue*)queue;
do{
}while(lfq->pop());
};

void* push(void* queue)
{
lock_free_queue* lfq = (lock_free_queue*)queue;
for(int i=0;i<count_per_thread_push/4;++i)
{
unsigned long long now = rdtsc();
lfq->push(now);
lfq->push(now);
lfq->push(now);
lfq->push(now);
}

};

void* push_end(void* queue)
{
lock_free_queue* lfq = (lock_free_queue*)queue;
for(int i=0;i<1000;++i)
{
lfq->push(0);
}
}
int main(void)
{
pthread_t* thread_pop = (pthread_t*) malloc(10*sizeof( pthread_t));
pthread_t* thread_push = (pthread_t*) malloc(10*sizeof( pthread_t));
pthread_t* thread_push_end = (pthread_t*) malloc(sizeof( pthread_t));
lock_free_queue lfq;

for(int i=0;i<10;++i)
{
pthread_create(&thread_push[i],NULL,push,&lfq);
}


for(int i=0;i<10;++i)
{
pthread_create(&thread_pop[i],NULL,pop,&lfq);
}

for(int i=0;i<10;++i) //make push end
{
pthread_join(thread_push[i],NULL);
}

pthread_create(thread_push_end,NULL,push_end,&lfq); //push end signal

for(int i=0;i<10;++i) //wait pop quit
{
pthread_join(thread_pop[i],NULL);
}

if( NULL != thread_pop )
{
free(thread_pop);
thread_pop = NULL;
}
if( NULL != thread_pop )
{
free(thread_push);
thread_push = NULL;
}
if( NULL != thread_push_end )
{
free( thread_push_end );
thread_push_end = NULL;
}


}

寻找自我 2012-09-04
  • 打赏
  • 举报
回复
游戏规则传不上来,说是有非法词组,情何以堪。

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧