2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -6,24 +6,24 @@ IPython 中用 `magic` 命令 `%timeit` 来计时。
In [1]:
```
```py
%timeit [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
```
```
```py
1000000 loops, best of 3: 456 ns per loop
```
In [2]:
```
```py
%timeit (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25)
```
```
```py
10000000 loops, best of 3: 23 ns per loop
```
@@ -36,7 +36,7 @@ In [2]:
In [3]:
```
```py
from numpy.random import rand
values = rand(10000,4)
lst = [list(row) for row in values]
@@ -46,24 +46,24 @@ tup = tuple(tuple(row) for row in values)
In [4]:
```
```py
%timeit for row in lst: list(row)
```
```
```py
100 loops, best of 3: 4.12 ms per loop
```
In [5]:
```
```py
%timeit for row in tup: tuple(row)
```
```
```py
100 loops, best of 3: 2.07 ms per loop
```
@@ -74,12 +74,12 @@ In [5]:
In [6]:
```
```py
%timeit for row in lst: a = row[0] + 1
```
```
```py
The slowest run took 12.20 times longer than the fastest. This could mean that an intermediate result is being cached
100 loops, best of 3: 3.73 ms per loop
@@ -87,12 +87,12 @@ The slowest run took 12.20 times longer than the fastest. This could mean that a
In [7]:
```
```py
%timeit for row in tup: a = row[0] + 1
```
```
```py
100 loops, best of 3: 3.82 ms per loop
```