Skip to content

Commit 330c3d5

Browse files
committed
新增大数据测试
1 parent 7ea1570 commit 330c3d5

2 files changed

Lines changed: 1000059 additions & 0 deletions

File tree

big_data.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# encoding: utf-8
2+
__author__ = 'zhanghe'
3+
4+
"""
5+
大数据效率测试
6+
"""
7+
8+
import random
9+
import tools.time_log
10+
11+
12+
@tools.time_log.time_log
13+
def create_data():
14+
"""
15+
创建大数据
16+
"""
17+
file_name = 'static/csv/data.csv'
18+
with open(file_name, 'wb') as f:
19+
for key in xrange(1000000):
20+
row = '%s\t%s\n' % (key, random.randint(100, 200))
21+
print row
22+
f.write(row)
23+
24+
25+
@tools.time_log.time_log
26+
def read_data():
27+
"""
28+
读取大数据
29+
"""
30+
file_name = 'static/csv/data.csv'
31+
with open(file_name) as f:
32+
for line in f:
33+
print line.rstrip('\n').split('\t')
34+
35+
36+
if __name__ == '__main__':
37+
# create_data()
38+
read_data()
39+
40+
41+
"""
42+
运行状况:
43+
44+
方法create_data运行时间:19.08S
45+
46+
方法read_data运行时间:65.21S
47+
48+
读取文件时的状态
49+
zhanghe@ubuntu:~/code/python$ top
50+
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
51+
10059 zhanghe 20 0 12656 4532 2632 R 95.2 0.2 0:13.74 python
52+
53+
54+
zhanghe@ubuntu:~/code/python$ du -h static/csv/data.csv
55+
11M static/csv/data.csv
56+
57+
zhanghe@ubuntu:~/code/python$ less static/csv/data.csv
58+
59+
"""

0 commit comments

Comments
 (0)