Skip to content

Commit

Permalink
Faster Python - 10th version
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed May 17, 2024
1 parent a6af425 commit 0a8b4fc
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/faster_python.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,44 @@ print(z)

---

### Code is too universal

```python
import dis

def add_two_numbers(x, y):
return x + y


class Foo:
def __init__(self, value):
self._value = value

def __add__(self, other):
return Foo(self._value + other._value)

def __str__(self):
return "*" * self._value


def test_adding():
f1 = Foo(1)
f2 = Foo(2)

print(add_two_numbers(123, 456))
print(add_two_numbers("foo", "bar"))
print(add_two_numbers([1,2,3], [4,5,6]))
print(add_two_numbers((1,2,3), (4,5,6)))
print(add_two_numbers(f1, f2))


test_adding()
dis.dis(add_two_numbers)
dis.dis(test_adding)
```

---

## Where's the problem?

```python
Expand Down

0 comments on commit 0a8b4fc

Please sign in to comment.