質問編集履歴
2
何回か試してみました
test
CHANGED
File without changes
|
test
CHANGED
@@ -95,3 +95,61 @@
|
|
95
95
|
|
96
96
|
|
97
97
|
また、一般にこのような場合はこっちの方法が良いみたいなものがあれば教えて欲しいです。
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
# 追記:再現性について
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
for i in range(3):
|
106
|
+
|
107
|
+
# 方法1
|
108
|
+
|
109
|
+
start = time.time()
|
110
|
+
|
111
|
+
review = []
|
112
|
+
|
113
|
+
with open("review") as r:
|
114
|
+
|
115
|
+
for line in r:
|
116
|
+
|
117
|
+
review.append(line)
|
118
|
+
|
119
|
+
elapsed_time = time.time() - start
|
120
|
+
|
121
|
+
print ("method1 :{0}".format(elapsed_time) + "[sec]")
|
122
|
+
|
123
|
+
# 方法2
|
124
|
+
|
125
|
+
start = time.time()
|
126
|
+
|
127
|
+
with open("review") as r:
|
128
|
+
|
129
|
+
review = r.read().split("\n")
|
130
|
+
|
131
|
+
elapsed_time = time.time() - start
|
132
|
+
|
133
|
+
print ("method2 :{0}".format(elapsed_time) + "[sec]")
|
134
|
+
|
135
|
+
print("")
|
136
|
+
|
137
|
+
```
|
138
|
+
|
139
|
+
結果
|
140
|
+
|
141
|
+
method1 :7.316558837890625[sec]
|
142
|
+
|
143
|
+
method2 :132.77226877212524[sec]
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
method1 :7.942023038864136[sec]
|
148
|
+
|
149
|
+
method2 :132.67939019203186[sec]
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
method1 :8.178030967712402[sec]
|
154
|
+
|
155
|
+
method2 :134.0433452129364[sec]
|
1
コードに不必要な変数が宣言されていたので消しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -21,8 +21,6 @@
|
|
21
21
|
start = time.time()
|
22
22
|
|
23
23
|
review = []
|
24
|
-
|
25
|
-
label = []
|
26
24
|
|
27
25
|
with open("review") as r:
|
28
26
|
|