фикс rust.rs и добавил speedtest

This commit is contained in:
Viner Abubakirov
2025-09-15 12:30:20 +05:00
parent 8eccad2523
commit 956acf18d1
2 changed files with 102 additions and 2 deletions

View File

@@ -134,7 +134,7 @@ impl Div<Complex> for f64 {
#[derive(Debug)]
struct Args {
size: u8,
size: u32,
depth: u8,
g2: Complex,
g3: Complex,
@@ -192,7 +192,7 @@ fn main() {
println!("{}", fractal(args.size, args.depth, args.g2, args.g3));
}
fn fractal(size: u8, depth: u8, g2: Complex, g3: Complex) -> String {
fn fractal(size: u32, depth: u8, g2: Complex, g3: Complex) -> String {
let xi: f64 = -2.0;
let yi: f64 = -2.0;
let xf: f64 = 2.0;

100
speedtest.py Normal file
View File

@@ -0,0 +1,100 @@
import time
import subprocess
class SpeedTest:
def __init__(
self,
size: int = 128,
depth: int = 8,
g2: float = 1.0,
g3: float = 0.0,
) -> None:
self.size = size
self.depth = depth
self.g2 = g2
self.g3 = g3
def rust(self):
def runner():
cmd = [
"./main-rs",
"--size",
str(self.size),
"--depth",
str(self.depth),
"-g2",
str(self.g2),
"-g3",
str(self.g3),
]
result = self._runner(cmd)
cmd = ["rm", "main-rs"]
self._runner(cmd)
return result
cmd = ["rustc", "main.rs", "-o", "main-rs"]
self._runner(cmd)
return runner
def golang(self):
def runner():
cmd = [
"./main-go",
"--size",
str(self.size),
"--depth",
str(self.depth),
"-g2",
str(self.g2),
"-g3",
str(self.g3),
]
result = self._runner(cmd)
cmd = ["rm", "main-go"]
self._runner(cmd)
return result
cmd = ["go", "build", "-o", "main-go", "main.go"]
self._runner(cmd)
return runner
def python(self):
def runner():
cmd = [
"python3",
"./main.py",
"--size",
str(self.size),
"--depth",
str(self.depth),
"-g2",
str(self.g2),
"-g3",
str(self.g3),
]
return self._runner(cmd)
return runner
def _runner(self, cmd: list[str]):
return subprocess.run(cmd, text=True, capture_output=True).stdout.strip()
def timer(func):
start = time.time()
r = func()
print(len(r))
end = time.time()
return end - start
def main():
speedtest = SpeedTest(1000)
print("python", timer(speedtest.python()))
print("golang", timer(speedtest.golang()))
print("rust", timer(speedtest.rust()))
if __name__ == "__main__":
main()