Created
September 15, 2022 03:08
-
-
Save merlinnusr/4683c18b5dac10a56fc25f831dfcee86 to your computer and use it in GitHub Desktop.
Algorith Performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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