Commit 792cd95
authored
Here is an optimized version of your code.
The multiplication and conversion to int are very fast, but calling `len()` on a Python string first computes the length.
To minimize overhead, we can use integer arithmetic to avoid the float operations in `len(s)*0.3`. Multiplying by 0.3 is equivalent to multiplying by 3 and integer dividing by 10.
Here's the optimized code.
This avoids floating point multiplication and `int()` casting, and is slightly faster.
All comments and signatures are preserved.
1 parent c4a24e8 commit 792cd95
1 file changed
+7
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| |||
0 commit comments