I tested the run-time of a python script, for a "Metropolis Algorithm" in Windows 11 [Version 10.0.22621.1265], WSL2 [5.15.79.1-microsoft-standard-WSL2] on Windows 11 with Ubuntu terminal environment [Installed version 2204.1.8.0], and Ubuntu 22.04. Each one with Python 3.10.6 version, ran on the same machine with Intel(R) Core(TM) i5-8250U CPU @ 1.60 GHz, 1801 Mhz, 4 Core(s), 8 Logical Processor(s).
The run was for Ising Model dynamics using the metropolis algorithm.
The code:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import colors
import time
startTime = time.time()
T = 1.5
N = 1000
up = 1
down = -1
field = [up, down]
colormap = colors.ListedColormap(["white","black"])
s = np.random.choice(field, N*N).reshape(N, N)
def update(data):
global s, T
newS = s.copy()
for i in range (N):
for j in range(N):
sorroundSpin = (newS[i, (j-1)%N] + newS[i, (j+1)%N]
+ newS[(i-1)%N, j] + newS[(i+1)%N, j])
E = -2*newS[i, j]*sorroundSpin
if E>0:
newS[i, j] *= -1
else:
r = np.random.rand()
#print(r)
if r < np.exp((2*E)/T):
newS[i, j] *= -1
mat.set_data(newS)
s = newS
print("Simulating Generation ",data)
if data%10 == 0:
elapsed = time.time() - startTime
print("Elapsed Time: ",elapsed)
return [mat]
fig, ax = plt.subplots()
mat = plt.imshow(s, cmap=colormap)
ani = animation.FuncAnimation(fig, update, interval=50, save_count=200)
#ani.save('ising3.gif', writer='imagemagick', fps=60)
plt.show()

The first part was a consistency run evaluation for run-time to generate the random configuration of 1000x1000 grids with 0/1 values and move up a generation. Ubuntu 22.04 runs were the fastest and most consistent with an average of 4.979 sec(s) and a standard deviation of 0.342 sec(s), followed by WSL2 with an average of 7.200 sec(s) and a standard deviation of 1.902 sec(s) and Windows 11 with an average of 7.389 sec(s) and a standard deviation of 1.455 sec(s).

Secondly, the run-time evaluation for a few generations with a random run. Ubuntu 22.04 run was the fastest (34.18% faster than Windows 11 and 25.78% faster than WSL2), followed by WSL2 (11.32% faster than Windows 11) and Windows 11.

Ubuntu 22.04 was overall, the fastest and most consistent in run-time, followed by WSL2 on Windows 11 and Windows 11.
Comments