Skip to content

Instantly share code, notes, and snippets.

@polyglothacker
Created May 18, 2022 05:10
Show Gist options
  • Save polyglothacker/5efa2e2dde144e74a628cc024035ff6e to your computer and use it in GitHub Desktop.
Save polyglothacker/5efa2e2dde144e74a628cc024035ff6e to your computer and use it in GitHub Desktop.
import requests
import time
class APITest:
def __init__(self, api):
t1 = time.time()
requests.get(api)
t2 = time.time()
self.time_taken = t2 - t1
def __str__(self):
return f'Time taken: {self.time_taken}'
if __name__ == "__main__":
a = APITest('https://api.drishti.com/v1/toyota/stations')
print(a)
@polyglothacker
Copy link
Author

polyglothacker commented May 18, 2022

Use this class as a base for developing higher benchmark test classes (or a single class) which can do

  1. Burst testing: (defined as concurrency = k)
  2. Linearly ramped up testing (defined as y = ax)
  3. Sine wave/cos wave testing (defined as y = sinx or y = cosx)
  4. Exponentially ramped up testing (defined as y = e**x)

Where x => Either the # of the test (1, 2, 3 ...) or x => time
and y => number of test requests sent at a given time (approximately rps => requests per second)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment