Skip to content

Instantly share code, notes, and snippets.

@TomoG29
Created June 30, 2026 08:06
Show Gist options
  • Select an option

  • Save TomoG29/c01d1e7c42f63d78cf857614a60a44e1 to your computer and use it in GitHub Desktop.

Select an option

Save TomoG29/c01d1e7c42f63d78cf857614a60a44e1 to your computer and use it in GitHub Desktop.
Blog_DifferentialProcessTime.py
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