Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/output/timingStats.py
169674 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file timingStats.py
15
# @author Michael Behrisch
16
# @author Daniel Krajzewicz
17
# @date 2010-10-15
18
19
"""
20
This script executes a config repeatedly and measures the execution time,
21
computes the mean values and deviation.
22
"""
23
from __future__ import absolute_import
24
from __future__ import print_function
25
import os
26
import sys
27
import subprocess
28
import numpy
29
from optparse import OptionParser
30
from datetime import datetime
31
32
sumoBinary = os.environ.get("SUMO_BINARY", os.path.join(
33
os.path.dirname(sys.argv[0]), '..', '..', 'bin', 'sumo'))
34
35
# initialise
36
optParser = OptionParser()
37
optParser.add_option("-v", "--verbose", action="store_true",
38
default=False, help="tell me what you are doing")
39
optParser.add_option("-c", "--configuration",
40
help="sumo configuration to run", metavar="FILE")
41
optParser.add_option("-a", "--application", default=sumoBinary,
42
help="application to run", metavar="FILE")
43
optParser.add_option("-r", "--repeat", type="int", default="20",
44
help="how many times to run")
45
# parse options
46
(options, args) = optParser.parse_args()
47
48
app = options.application
49
elapsed = []
50
for run in range(options.repeat):
51
before = datetime.now()
52
subprocess.call([app, '-c', options.configuration])
53
td = datetime.now() - before
54
elapsed.append(td.microseconds + 1000000 * td.seconds)
55
a = numpy.array(elapsed)
56
print("%.4f %.4f" % (a.mean() / 1000, a.std() / 1000))
57
58