I did some Python performance comparison on PC and smartphone and results were confusing.
PC: i7-8750H / 32GB RAM / 1TB SSD / Windows 10
Smartphone: Galaxy S10 with Termux Linux emulator on Android 11
First one was simple Monte Carlo simulation with following code.
import random
import time
def monte_carlo_pi(n_samples: int):
acc = 0
for i in range(n_samples):
x = random.random()
y = random.random()
if (x**2 + y**2) < 1.0:
acc += 1
return 4.0 * acc / n_samples
start_time = time.time()
print(monte_carlo_pi(10000000))
print(time.time()-start_time)
Surprisingly, it took about 5.2sec for PC and 2.7sec for smartphone.
Second was using pandas with some dataframe operations.
import pandas as pd
import time
start_time = time.time()
df = pd.DataFrame(
[ [21, 72, -67],
[23, 78, 62],
[32, 74, 54],
[52, 54, 76],
[0, 23, 66],
[2, 1, 2] ],
index = [11, 22, 33, 44, 55, 66],
columns = ['a', 'b', 'c'])
df2 = pd.DataFrame()
df2 = pd.concat([df2, df['a']], axis=1)
df2 = pd.concat([df2, df['c']], axis=1)
print(df2)
print(time.time()-start_time)
This time, PC was about 0.007sec and smartphone was about 0.009sec, but the actual time from exec. to finish for smartphone was about 2 sec. My guess is that it takes longer for smartphone to load lengthy pandas package but not sure.
- Is ARM processor faster on simple repetitive calculations? Or is or isn't either one of the processor utilizing multi-core capability?
- Is smartphone relatively slow on reading lengthy packages as observed above?
- Is there a better way to measure overall Python performance between PC and smartphone?