commit d98a156332d4986e49d4e49fcc9de831bb497091
Author: Andrew Laack <andrew@laack.co>
Date: Thu, 9 Oct 2025 00:05:17 -0500
Fib in c and in python
Diffstat:
3 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1 @@
+*.out
diff --git a/comparisons/fib-in-py.py b/comparisons/fib-in-py.py
@@ -0,0 +1,16 @@
+def calculate(p1, p2):
+ return p1 + p2
+
+
+for i in range(0,10000):
+ prior = 0
+ current = 1
+ for x in range(0,90):
+ print(current)
+ nc = calculate(prior, current)
+ prior = current
+ current = nc
+
+# real 0m2.992s
+# user 0m1.763s
+# sys 0m1.222s
diff --git a/fib-in-c.c b/fib-in-c.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <stdint.h>
+
+unsigned long long calculate(unsigned long long p2, unsigned long long p1){
+ return p2 + p1;
+}
+
+int main(){
+
+ for(int i = 0; i < 10000; ++i){
+ unsigned long long prior = 0;
+ unsigned long long current = 1;
+ for (int i = 0; i <= 90; ++i) {
+ printf("%llu\n", current);
+ unsigned long long int nc = calculate(prior, current);
+ prior = current;
+ current = nc;
+ }
+ }
+
+}
+
+// real 0m1.299s
+// user 0m0.280s
+// sys 0m1.017s