File size: 1,775 Bytes
00329f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import torch
import torchvision.models as models
import time
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from qiskit import QuantumCircuit
from torch import nn

# === 1. ResNet50 Inference Benchmark ===
def benchmark_resnet50():
    model = models.resnet50(pretrained=False).eval()
    input_data = torch.randn(64, 3, 224, 224)
    start = time.time()
    with torch.no_grad():
        _ = model(input_data)
    end = time.time()
    return end - start

# === 2. GAN Benchmark ===
class SimpleGAN(nn.Module):
    def __init__(self):
        super(SimpleGAN, self).__init__()
        self.fc = nn.Sequential(
            nn.Linear(100, 256),
            nn.ReLU(),
            nn.Linear(256, 784),
            nn.Tanh()
        )
    def forward(self, z):
        return self.fc(z)

def benchmark_gan():
    model = SimpleGAN()
    z = torch.randn((1, 100))
    start = time.time()
    _ = model(z)
    end = time.time()
    return end - start

# === 3. QAOA Simulation (Mock) ===
def benchmark_qaoa(qubits=1000):
    start = time.time()
    qc = QuantumCircuit(qubits)
    for i in range(qubits):
        qc.h(i)
    qc.barrier()
    end = time.time()
    return end - start

# === 4. Save Results ===
def run_benchmarks():
    results = {
        "ResNet50 (s)": benchmark_resnet50(),
        "GAN Gen (s)": benchmark_gan(),
        "QAOA 1000q (s)": benchmark_qaoa()
    }
    df = pd.DataFrame([results])
    df.to_csv("benchmark_results.csv", index=False)

    # Plot
    plt.figure(figsize=(10, 6))
    plt.bar(results.keys(), results.values(), color='purple')
    plt.ylabel("Temps (s)")
    plt.title("Benchmarks MONSTERDOG Multi-Noeuds")
    plt.savefig("benchmark_plot.png")
    plt.close()

if __name__ == "__main__":
    run_benchmarks()