Skip to content

Commit

Permalink
add cython
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Sinton committed Dec 7, 2024
1 parent 6734f06 commit cffe3a6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ rm v/code
rm emojicode/code emojicode/code.o
rm -f chez/code.so
rm -rf clojure/classes clojure/.cpcache
rm cobol/main
rm cobol/main
rm -f cython/code.c cython/code
1 change: 1 addition & 0 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ emojicodec emojicode/code.emojic
echo '(compile-program "chez/code.ss")' | chez --optimize-level 3 -q
(cd clojure && mkdir -p classes && clojure -Sdeps '{:paths ["."]}' -M -e "(compile 'code)")
cobc -I /opt/homebrew/include/ -O -O2 -O3 -Os -x -o cobol/main cobol/main.cbl
cd cython && pip install cython && cython code.pyx --embed && clang $(python-config --includes) $(python-config --libs) -lpython3.13 -O3 code.c -o code
19 changes: 19 additions & 0 deletions loops/cython/code.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import random


def main():
cdef int u, r, i, j
cdef int a[10000]

u = int(sys.argv[1]) # Get an input number from the command line
r = random.randint(0, 10000) # Get a random number 0 <= r < 10k
a = [0] * 10000 # Array of 10k elements initialized to 0
for i in range(10000): # 10k outer loop iterations
for j in range(100000): # 100k inner loop iterations, per outer loop iteration
a[i] += j % u # Simple sum
a[i] += r # Add a random value to each element in array
print(a[r]) # Print out a single element from the array


main()
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ run "MAWK" "mawk -f ./awk/code.awk 40"
run "Clojure" "java -cp clojure/classes:$(clojure -Spath) code 40"
run "Babashka" "bb -cp clojure -m code 40"
run "COBOL" "./cobol/main"
run "Cython" "./cython/code"

0 comments on commit cffe3a6

Please sign in to comment.