```python
# sources: 
#     https://youtu.be/qleGSnrnxgc?t=2696
#     https://appdividend.com/2020/11/23/python-string-substitution-example/
#     https://stackoverflow.com/questions/5622976/how-do-you-calculate-program-run-time-in-python
import timeit
from sympy import *; x = symbols('x')
```


```python
start0 = timeit.default_timer()

#lamdify specifies an input and output expression
#this runs as a basic python function
f = lambdify(x,x**2)  
f(3)

stop0 = timeit.default_timer()
print('Time: ', stop0 - start0, "           f(3) = ",f(3))  
diff0 = stop0 - start0
```

    Time:  0.2884548999999996            f(3) =  9



```python
start1 = timeit.default_timer()

# since python is slow, we can swap sympy for numpy to do 
# faster calculations (faster run time)
f = lambdify(x,x**2, 'numpy')  
f(3)

stop1 = timeit.default_timer()
print('Time: ', stop1 - start1, "           f(3) = ",f(3))  
diff1 = stop1 - start1
```

    Time:  0.0008004000000001454            f(3) =  9



```python
# returned values from first test
# Time:  0.2861325999999984
# Time:  0.0007134999999998115
def percentage_change(diff0, diff1):
    if diff1 != 0 :
        return float(diff0 - diff1) / abs(diff1) * 100
    else:
        return "undefined"
    
    
# Our Percent Change is 40002% by offloading the math to numpy.
# This is useful for real world application using sympy    
print("Numpy is %s percent faster than Sympy for doing arithmetic." % int(percentage_change(diff0, diff1)))
```

    Numpy is 35938 percent faster than Sympy for doing arithmetic.


857fb0bb1a7d73aee43dd97365f6af615fdcbf98
ipynb
Jupyter Notebook
Personal_Projects/Comparing_Run_Times_Sympy_vs_Numpy.ipynb
NSC9/Sample_of_Work
8f8160fbf0aa4fd514d4a5046668a194997aade6
MIT
Personal_Projects/Comparing_Run_Times_Sympy_vs_Numpy.ipynb
NSC9/Sample_of_Work
8f8160fbf0aa4fd514d4a5046668a194997aade6
MIT
Personal_Projects/Comparing_Run_Times_Sympy_vs_Numpy.ipynb
NSC9/Sample_of_Work
8f8160fbf0aa4fd514d4a5046668a194997aade6
MIT
Qwen/Qwen-72B
1. YES
2. YES