Skip to content

Commit 282665a

Browse files
committed
Small tweaks in wording and corrections
1 parent 2aeb4e9 commit 282665a

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

examples/sum-example.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Please navigate to a folder suitable to you and clone into the pybm sum example
1212
repository:
1313

1414
```shell
15-
git clone https://github.com/nicholasjng/pybm-sum-example.git
16-
cd pybm-sum-example
15+
git clone https://github.com/nicholasjng/pybm-sum-example.git sum-example
16+
cd sum-example
1717
git checkout master
1818
```
1919

@@ -61,9 +61,9 @@ better?
6161

6262
## Reducing it to linear time
6363

64-
Alright, maybe the improvement here is already too obvious. Of course, we can
65-
easily cut the complexity by summing the actual numbers instead of ones. The new
66-
functions then looks like this:
64+
Alright, maybe the improvement here is already obvious. Of course, we can easily
65+
cut the complexity by summing the actual numbers instead of ones. The new
66+
function then looks like this:
6767

6868
```python
6969
def my_sum(n: int):
@@ -75,8 +75,8 @@ def my_sum(n: int):
7575
```
7676

7777
But we need to adhere to a normal development workflow here! So instead of just
78-
hacking the new algorithm and pushing the changes, we need to create a feature
79-
branch (we're calling it "linear-time"), containing our improved algorithm. The
78+
hacking the new algorithm and pushing the changes, we should create a feature
79+
branch (we're calling it "linear-time") containing our improved algorithm. The
8080
branch is already present in the example repository that you previously checked
8181
out. You can create a pybm benchmark environment for it with the following
8282
command, run from the repository root folder on `master`:
@@ -122,7 +122,7 @@ def my_sum(n: int):
122122
return n * (n + 1) // 2
123123
```
124124
125-
No more loops, no `if`s, no buts: We have reduced the summation problem to a
125+
No more loops, no `if`s, no buts: We have reduced the summation to a
126126
_constant time_ problem! This looks very promising. Again, this algorithm is
127127
already implemented on another branch called `constant-time`, for which we can
128128
also create a benchmark environment:
@@ -171,18 +171,19 @@ if __name__ == "__main__":
171171
pybm.run(context=globals())
172172
```
173173
174-
Aside from some sys-path-hacking to get the python path set up correctly, the
175-
test file is very simple: We import our function `my_sum`, sum up all numbers
176-
from 1 to 10000, and run the benchmark when running the module as `__main__`.
177-
Everything else is set up by pybm's default configuration, so we do not need to
178-
tweak more options and spend more time to get up and running.
174+
Aside from some sys-path-hacking to get the python path set up correctly
175+
(which you should just ignore right now), the test file is very simple: We
176+
import our function `my_sum`, sum up all numbers from 1 to 10000, and run the
177+
benchmark when executing the module as `__main__`. Everything else is set up by
178+
pybm's default configuration, so we do not need to tweak more options and spend
179+
more time to get up and running.
179180
180181
NOTE: The above benchmark file is the same on all three branches, and there is a
181182
good reason for it! When comparing the different implementations, we do need the
182-
benchmarking procedure to stay the same.
183+
benchmarking _procedure_ itself to stay the same to yield comparable results.
183184
184185
```shell
185-
# Tell pybm to run the benchmarks in the benchmarks directory in all environments.
186+
# Tells pybm to run the benchmarks in the benchmarks directory in all environments.
186187
pybm run benchmarks/ --all
187188
188189
Starting benchmarking run in environment 'root'.
@@ -207,9 +208,9 @@ And there we have it! Instead of the manual rinse-and-repeat in a checkout
207208
branch->benchmark->save-results kind of workflow, we obtained all the results we
208209
need in one single command. Very nice!
209210
210-
## The numbers
211+
## And finally... the numbers
211212
212-
And finally, we need to check how big our improvements actually are (or rather,
213+
Lastly, we need to check how big our improvements actually are (or rather,
213214
if we have achieved any in the first place!). This is handled by the
214215
`pybm compare` command, which compares all measured results to a "frame of
215216
reference" branch, which is taken to be the baseline for performance
@@ -231,8 +232,8 @@ we actually... 10-million-x-ed it. Great work! Our constant time algorithm is
231232
definitely ready for a pull request :-)
232233
233234
These are of course video game numbers, obtained by algorithmic improvements.
234-
More common real-world examples would see improvements in the two-to-three digit
235-
percentage range, but this example above does happen from time to time!
235+
More common real-world examples would see improvements in the one-to-three digit
236+
percentage range, but the example you see above does happen from time to time.
236237
237238
And with that, the first pybm tutorial is finished. I hope you enjoyed it, and
238239
catch you on the next one!

0 commit comments

Comments
 (0)