Last active
September 25, 2020 16:15
-
-
Save davlgd/2782322 to your computer and use it in GitHub Desktop.
PCi DiRT Shodown Py Bench Tool
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# Copyright (c) 2012 LEGRAND David <[email protected]> | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
from subprocess import Popen | |
from sys import exit | |
import os | |
# la fonction qui lit le résultat dans le fichier XML de sortie | |
def readResult(Path): | |
from xml.dom import minidom | |
xmldoc = minidom.parse(Path) | |
fps = xmldoc.getElementsByTagName("average")[0].attributes["av_fps"].value | |
return str("%.2f" % float(fps)) | |
# la fonction qui lance le benchmark et qui affiche le résultat à l'écran | |
def benchmark(i): | |
# Les variables utiles concernant le jeu | |
# Attention, on utilise un "/" pour séparer les répertoires, non un "\" | |
### VALEURS A MODIFIER AVANT DE LANCER LES TESTS ### | |
d3BasePath = u"C:/XXX/Steam/SteamApps/common/dirt showdown" | |
resultsPath = u"C:/Users/XXX/Documents/My Games/DiRT Showdown/benchmarks" | |
d3Exe = u"showdown.exe" | |
d3Xml = u"example_benchmark.xml" | |
d3FullPath = d3BasePath + "/" + d3Exe | |
d3BenchCommand = u"-benchmark" | |
# On nettoie le chemin de base des fichiers de résultats | |
if os.path.exists(resultsPath): | |
for file in os.listdir(resultsPath): | |
os.remove(resultsPath + "/" + file) | |
# On place le tout dans un try / except pour remonter les éventuels soucis | |
try: | |
# on lance le benchmark et on attend qu'il se termine | |
# on notera la présence de CWD, permettant de calmer la protection du jeu | |
launch = Popen([d3FullPath, d3BenchCommand, d3Xml], cwd=d3BasePath) | |
launch.wait() | |
# Si l'on utilise Steam, le process lancé se termine et passe à un autre | |
# Il faut presser sur Entrée pour la suite | |
if "SteamApps/common/" in d3FullPath: | |
print u" Appuyez sur la touche Entrée pour continuer..." | |
raw_input() | |
# on récupère le résultat qu'on affiche | |
result = readResult(resultsPath + "/" + os.listdir(resultsPath)[0]) | |
print u" Résultat du test #{0} : {1} fps".format(str(i+1), result) | |
# En cas d'erreur, on affiche un message et on quitte l'application | |
except Exception as e: | |
print u" Une erreur est intervenue durant le test." | |
exit(1) | |
# Sinon, on renvoie le résultat | |
return result | |
#################### | |
#################### | |
# On définit une valeur de moyenne | |
avg = 0. | |
nb = 3 | |
# on affiche le texte de mise en forme | |
print " PCi DiRT Showdown Py Bench Tool" | |
print " -------------------------------" | |
# on lance plusieurs fois le test | |
# à chaque lancement on incrémente la moyenne | |
for i in range(nb): | |
avg = avg + float(benchmark(i)) | |
# on affiche la moyenne sous forme d'un flottant avec deux décimales | |
print u"\n Moyenne obtenue : %s fps" % str("%.2f" % (avg / float(nb))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment