Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import time
- import subprocess as sp
- algos = [
- "bitcoin",
- "blake",
- "blakecoin",
- "c11",
- "deep",
- "dmd-gr",
- "doom",
- "fresh",
- "fugue256",
- "groestl",
- "keccak",
- "jackpot",
- "luffa",
- "lyra2v2",
- "myr-gr",
- "nist5",
- "penta",
- "quark",
- "qubit",
- "sia",
- "skein",
- "s3",
- "whirl",
- "whirlpoolx",
- "x11",
- "x13",
- "x14",
- "x15",
- "x17",
- "vanilla",
- "neoscrypt"
- ]
- GPU_IDX = 0
- MAX_TIME = 60
- speed_mult = {"gh/s": 10**9, "mh/s": 10**6, "kh/s": 10*3, "h/s": 1}
- def parse(stdout, stderr):
- data = []
- for line in stderr.splitlines():
- try:
- speed, unit = line.split("] Total: ", 1)[1].strip().split(" ")
- speed = int(float(speed) * speed_mult[unit.lower()])
- data.append(speed)
- except IndexError:
- continue
- except KeyError:
- print(stdout)
- print(stderr)
- exit(-1)
- return data
- def run(command, verbose=None):
- proc = sp.Popen(command.split(" "), stdout=sp.PIPE, stderr=sp.PIPE)
- if verbose:
- print('Started:', command, '(pid = ' + str(proc.pid) + ')')
- result = proc.communicate()
- return map(bytes.decode, result)
- def benchmark():
- nvidia_cmd = "nvidia-smi --query-gpu=pci.bus_id,enforced.power.limit,clocks.sm,clocks.mem --format=csv,noheader,nounits -i %d" % GPU_IDX
- for algo in set(algos):
- command = "timeout %(timeout)ds ./ccminer -d %(gpu_idx)d --benchmark -t 1 -a %(algo)s -q --no-color --no-cpu-verify" % dict(
- timeout=MAX_TIME,
- gpu_idx=GPU_IDX,
- algo=algo
- )
- try:
- stdout, stderr = run(command, verbose=True)
- hashrates = parse(stdout, stderr)
- hashrate = max(hashrates)
- except KeyboardInterrupt:
- break
- except Exception as e:
- print("%s fail: %s" % (algo, e))
- continue
- nv_out, _ = run(nvidia_cmd)
- result = [algo] + [x.strip() for x in nv_out.split(", ") if x.strip()] + [str(hashrate)]
- with open("benchmarks.csv", "a+") as f:
- f.write(";".join(result) + "\n")
- print(result)
- print()
- time.sleep(5)
- benchmark()
Add Comment
Please, Sign In to add comment