File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ """
You can’t perform that action at this time.
0 commit comments