Skip to content

Commit b3f20ab

Browse files
committed
refactoring
1 parent b736075 commit b3f20ab

File tree

5 files changed

+47
-41
lines changed

5 files changed

+47
-41
lines changed

README.md

+3-41
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,6 @@
11
# python-learning
22
Learning Python
33

4-
## Decimal speed
5-
```python
6-
from timeit import Timer
7-
import platform
8-
9-
10-
def run(val, the_class):
11-
test = the_class(29.074)
12-
for c in range(10000):
13-
d = the_class(val)
14-
d + test
15-
d - test
16-
d * test
17-
d / test
18-
d ** 2
19-
#str(d)
20-
abs(d)
21-
22-
23-
if __name__ == '__main__':
24-
print('Python', platform.python_version(), 'running on', platform.system(), platform.release(), f'({platform.machine()})')
25-
a = Timer("run(123.345, float)", "from decimal_speed import run")
26-
print('FLOAT', a.timeit(1))
27-
b = Timer("run('123.345', Decimal)", "from decimal_speed import run; from decimal import Decimal")
28-
print('DECIMAL', b.timeit(1))
29-
print('DECIMAL / FLOAT', b.timeit(1) / a.timeit(1))
30-
c = Timer("run('123.345', np.float64)", "from decimal_speed import run; import numpy as np")
31-
print('np.float64', b.timeit(1))
32-
print('np.float64 / FLOAT', c.timeit(1) / a.timeit(1))
33-
34-
```
35-
Output:
36-
```shell
37-
Python 3.8.5 running on Windows 10 (AMD64)
38-
FLOAT 0.002470800000000002
39-
DECIMAL 0.010187999999999996
40-
DECIMAL / FLOAT 4.114297188755033
41-
np.float64 0.010377499999999998
42-
np.float64 / FLOAT 1.8912895338116917
43-
```
44-
4+
* Decimal
5+
* speed
6+
* precision

decimal/README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# python-learning
2+
Learning Python
3+
4+
## Decimal speed
5+
```python
6+
from timeit import Timer
7+
import platform
8+
9+
10+
def run(val, the_class):
11+
test = the_class(29.074)
12+
for c in range(10000):
13+
d = the_class(val)
14+
d + test
15+
d - test
16+
d * test
17+
d / test
18+
d ** 2
19+
#str(d)
20+
abs(d)
21+
22+
23+
if __name__ == '__main__':
24+
print('Python', platform.python_version(), 'running on', platform.system(), platform.release(), f'({platform.machine()})')
25+
a = Timer("run(123.345, float)", "from decimal_speed import run")
26+
print('FLOAT', a.timeit(1))
27+
b = Timer("run('123.345', Decimal)", "from decimal_speed import run; from decimal import Decimal")
28+
print('DECIMAL', b.timeit(1))
29+
print('DECIMAL / FLOAT', b.timeit(1) / a.timeit(1))
30+
c = Timer("run('123.345', np.float64)", "from decimal_speed import run; import numpy as np")
31+
print('np.float64', b.timeit(1))
32+
print('np.float64 / FLOAT', c.timeit(1) / a.timeit(1))
33+
34+
```
35+
Output:
36+
```shell
37+
Python 3.8.5 running on Windows 10 (AMD64)
38+
FLOAT 0.002470800000000002
39+
DECIMAL 0.010187999999999996
40+
DECIMAL / FLOAT 4.114297188755033
41+
np.float64 0.010377499999999998
42+
np.float64 / FLOAT 1.8912895338116917
43+
```
44+
File renamed without changes.

decimal/decimal_precision.py

Whitespace-only changes.
File renamed without changes.

0 commit comments

Comments
 (0)