Skip to content

Instantly share code, notes, and snippets.

@merlinnusr
Created September 15, 2022 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merlinnusr/4683c18b5dac10a56fc25f831dfcee86 to your computer and use it in GitHub Desktop.
Save merlinnusr/4683c18b5dac10a56fc25f831dfcee86 to your computer and use it in GitHub Desktop.
Algorith Performance
<?php
$n = 2048;
$A = [[]];
$B = [[]];
$C = [[]];
for ($i=0; $i < $n ; $i++) {
for ($j=0; $j < $n ; $j++){
$A[$i][$j] = rand();
$B[$i][$j] = rand();
$C[$i][$j] = rand();
}
}
$start = microtime(true);
for ($i=0; $i < $n; $i++) {
for ($j=0; $j < $n; $j++) {
for ($k=0; $k < $n; $k++) {
$C[$i][$j] += $A[$i][$k] * $B[$k][$j];
}
}
}
$end = microtime(true);
echo "Elapsed time in seconds ".$end-$start;
import random
import time
n = 2048
#populate the matrices with random values between 0.0 and 1.0
A = [[random.random() for row in range(n)] for col in range(n)]
B = [[random.random() for row in range(n)] for col in range(n)]
C = [[0 for row in range(n)] for col in range(n)]
start = time.time()
#matrix multiplication
for i in range(n):
for j in range(n):
for k in range(n):
C[i][j] += A[i][k] * B[k][j]
end = time.time()
print("Elapsed time in seconds {0}" .format (end-start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment