Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# DavidButts/Numba-Timing.py

Last active Jan 13, 2018
 #Written by David Butts #This code is an implementation of a Rule 30 Wolfram model written in Python. import numpy as np import time import numba @nb.jit #numba the function def Rule30_code(): Rule30 = np.zeros((1000,100000)) #initilize an array to run on (timesteps, width) Rule30[0,50] = 1 for y in range(Rule30.shape[0]-1): #iterate through grid for x in range(Rule30.shape[1]): #update the next rows values accoring to neighbor & self value right = x + 1 down = y + 1 left = x - 1 if right >= Rule30.shape[1]: right = 0 if Rule30[y,right] == 1 and Rule30[y,left] == 0: Rule30[down,x] = 1 elif Rule30[y,x] == 0 and Rule30[y,right] == 0 and Rule30[y,left] == 1: Rule30[down,x] = 1 elif Rule30[y,x] == 1 and Rule30[y,right] == 0 and Rule30[y,left] == 0: Rule30[down,x] = 1 else: Rule30[down,x] = 0 #average run time for 10 runs av_time = 0 for run in range(10): start = time.time() Rule30_code() end = time.time() av_time += (end-start) print(av_time/10.0, 'seconds for 10 runs')
to join this conversation on GitHub. Already have an account? Sign in to comment