Created
June 30, 2026 08:06
-
-
Save TomoG29/c01d1e7c42f63d78cf857614a60a44e1 to your computer and use it in GitHub Desktop.
Blog_DifferentialProcessTime.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sympy import * | |
| import time | |
| ProcessTime = 1000 | |
| def Differential(x): | |
| return 3*(x**2) | |
| def Self_f(x): | |
| return x**3 | |
| x = Symbol('x') | |
| f = x**3 | |
| start = time.perf_counter() | |
| for loop in range(ProcessTime): | |
| df = diff(f) | |
| for i in range(1, 6): | |
| df.subs(x, i) | |
| end = time.perf_counter() | |
| print(f"SymPy:{(end-start)*1000:.3f} ms") | |
| h = 1e-5 | |
| start = time.perf_counter() | |
| for loop in range(ProcessTime): | |
| for x in range(1,6): | |
| self_df = (Self_f(x+h) - Self_f(x) ) / h | |
| end = time.perf_counter() | |
| print(f"Self:{(end-start)*1000:.3f} ms") | |
| start = time.perf_counter() | |
| for loop in range(ProcessTime): | |
| for x in range(1,6): | |
| Differential(x) | |
| end = time.perf_counter() | |
| print(f"Assignment:{(end-start)*1000:.3f} ms") | |
| start = time.perf_counter() | |
| for loop in range(ProcessTime): | |
| for i in range(1, 6): | |
| df.subs(x, i) | |
| end = time.perf_counter() | |
| print(f"SymPy-CalcOnly:{(end-start)*1000:.3f} ms") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment