Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
python之效率问题.
社区开发
2855
views ·
5
replies ·
To
floor
Go
vala2012
deepin
2013-04-07 23:15
Author
a = []
for i in range(1, 1000000):
a.append(i)
for i in range(1, 10000):
a.remove(i)
Copy the Code
测试一下代码吧,是不是卡住了,不过喝一杯水的功夫就OK了.才删除1万条而已... 大家发现没有,看来PYTHON在处理大数据面前就比较弱,有关于处理大数据方面的工作就不要用PYTHON,我现在都很无奈拉.
PYTHON在处理大数据面前,确实让人..... 很无奈.
Reply
Like 0
Favorite
View the author
All Replies
leaeasy
deepin
2013-04-08 00:16
#1
楼主sb,试过xrange没有
Reply
Like 0
View the author
vala2012
deepin
2013-04-08 00:23
#2
楼主sb,试过xrange没有
看来 c/c++, 才是王道, 看来 数据结构,算法...在某种环境下是需要自己去写的. PYTHON不见那么智能.
由于为了兼容过多的东西,数据结构比较复杂,在某种方面就显得比较麻烦,
所以C/C++写的数据库系统就是证明这一点的.
我用1分钟写了一个简单的测试程序.
用链表来完成这样的事情,比较快,同样的事情,为何PYTHON怎么慢, 它的源码我没有看过, 我猜测应该是为了兼容很多操作,才导致的数据结构越来越复杂,性能也慢.
#include
#include
struct TestList
{
int data;
struct TestList *next;
};
int main(int argc, char *argv[])
{
puts("==========开始测试=============");
struct TestList *test = (struct TestList*)malloc(sizeof(struct TestList));
struct TestList *point = (struct TestList*)malloc(sizeof(struct TestList));
test->next = NULL;
puts("============添加=================");
for (int i = 0; i <= 1000000; i++)
{
struct TestList *add_test = (struct TestList*)malloc(sizeof(struct TestList));
add_test->data = i;
if (test->next == NULL)
{
test->next = add_test;
point = add_test;
}
else
{
point->next = add_test;
point = add_test;
}
}
puts("============删除================");
for (int i = 0; i <= 10000; i++)
{
struct TestList *remove = test->next;
test->next = remove->next;
//printf("%d\n", remove->data);
free(remove);
}
test->next = NULL;
free(point);
free(test);
puts("===========测试完毕============");
return 0;
}
Copy the Code
Reply
Like 0
View the author
lihongwu
deepin
2013-04-08 01:43
#3
楼主sb,试过xrange没有
看起来你们好像很熟的样子
:
Reply
Like 0
View the author
vala2012
deepin
2013-04-08 01:54
#4
[quote]楼主sb,试过xrange没有
看起来你们好像很熟的样子
:[/quote]
看起来大家都很熟的... :mrgreen: :mrgreen: :mrgreen:
Reply
Like 0
View the author
yfwz100
deepin
2013-08-25 00:31
#5
这个对比明显有问题啊。链表删除的只是最后一个元素,而python list默认的remove()方法是对比删除。如果删除有规律的话,这样 Python 也可以很快的:
#!/usr/bin/env python
a = [i for i in range(1,1000000)]
for i in range(1, 1000000):
a.pop()
Copy the Code
Reply
Like 0
View the author
Please
sign
in first
Featured Collection
Change
[Tutorial] deepin25 WSL Offline Installation Guide
UOS AI 2.8 Released! Three New Intelligent Agents & Major Evolution
Solid Q&A | deepin 25 Common Questions – The Immutable System Edition
New Thread
Popular Ranking
Change
WhatsApp doesn't work in the official Deepin browser!
Frequent kernel panic error since the last kernel update.
Popular Events
More
PYTHON在处理大数据面前,确实让人..... 很无奈.