Commits

arne...@web.de  committed e15f0b5

Moved the general test function into its own file to facilitate further tests.

  • Participants
  • Parent commits 7c4aa6d

Comments (0)

Files changed (2)

File for_loops_geschwindigkeitstest.py

 The general_test_function can be used to test the execution time of any number of functions. 
 """
 
+# First get the general test function
+from general_test_function import general_test_function
+
 def test_speed_of_for_loop_with_tuples(): 
     """Test the speed of two different for loops to see, if there's a difference.
 
         
 
 
-def general_test_function(functions, *args): 
-    """Compare the execution speed of different functions in the list of functions. 
-    
-@type functions: list of functions
-@param functions: [function1, function2, ...].
-@type args: any
-@param args: The argument(s) to pass to each of the functions. All functions get all and the same argument(s)"""
-    # We need the current time in seconds
-    from time import time
-
-    # First evaluate how long Python takes to get two times. We need to substract this value from the result to remove a constant offset. 
-    # Get the current time two times
-    start_time = time()
-    finish_time = time()
-    # Now calculate the difference which is how long Python takes for getting the time. 
-    #: The offset due to getting the time two times. This is less than 1*10e-5 s for me.
-    time_offset = finish_time - start_time
-
-    # Get start and stop times of all functions and put them into a list of tuples: (time_needed, function) - time needed first, so we can sort easily. 
-    #: A list of functions with execution speed
-    execution_times = []
-    for i in functions: 
-        # Start time of the function. 
-        start_time = time()
-        # Execute the function with the given argument
-        i(*args)
-        # Get the finish time
-        finish_time = time()
-        # Get the difference
-        time_needed = finish_time - start_time - time_offset
-        # append the tuple of execution time and function to the list of execution_speeds. 
-        execution_times.append((time_needed, i))
-    # Return the list of execution times, sorted by functions. 
-    return execution_times
-
-
-
 ### Self-Test ###
 if __name__ == "__main__": 
     # Test the speed for loops with tuples.

File general_test_function.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+"""Test the speed of function calls. 
+
+The general_test_function can be used to test the execution time of any number of functions. 
+"""
+
+def general_test_function(functions, *args): 
+    """Compare the execution speed of different functions in the list of functions. 
+    
+@type functions: list of functions
+@param functions: [function1, function2, ...].
+@type args: any
+@param args: The argument(s) to pass to each of the functions. All functions get all and the same argument(s)"""
+    # We need the current time in seconds
+    from time import time
+
+    # First evaluate how long Python takes to get two times. We need to substract this value from the result to remove a constant offset. 
+    # Get the current time two times
+    start_time = time()
+    finish_time = time()
+    # Now calculate the difference which is how long Python takes for getting the time. 
+    #: The offset due to getting the time two times. This is less than 1*10e-5 s for me.
+    time_offset = finish_time - start_time
+
+    # Get start and stop times of all functions and put them into a list of tuples: (time_needed, function) - time needed first, so we can sort easily. 
+    #: A list of functions with execution speed
+    execution_times = []
+    for i in functions: 
+        # Start time of the function. 
+        start_time = time()
+        # Execute the function with the given argument
+        i(*args)
+        # Get the finish time
+        finish_time = time()
+        # Get the difference
+        time_needed = finish_time - start_time - time_offset
+        # append the tuple of execution time and function to the list of execution_speeds. 
+        execution_times.append((time_needed, i))
+    # Return the list of execution times, sorted by functions. 
+    return execution_times
+
+
+
+### Self-Test ###
+if __name__ == "__main__": 
+    pass
+