sohojoe commited on
Commit
b255c4c
1 Parent(s): cb92ee4

implement num_steps

Browse files
Files changed (1) hide show
  1. api_test.py +16 -15
api_test.py CHANGED
@@ -6,6 +6,7 @@ import torch
6
 
7
  from api_helper import preprocess_image, encode_numpy_array
8
  clip_image_size = 224
 
9
 
10
  client = Client("http://127.0.0.1:7860/")
11
 
@@ -34,23 +35,23 @@ def test_image_as_payload(payload):
34
 
35
  # performance test for text
36
  start = time.time()
37
- for i in range(100):
38
  test_text()
39
  end = time.time()
40
- # print average time in seconds and in milliseconds and number of predictions per second
41
- print("Average time for text: ", (end - start) / 100, "s")
42
- print("Average time for text: ", (end - start) * 10, "ms")
43
- print("Number of predictions per second for text: ", 1 / ((end - start) / 100))
44
 
45
  # performance test for image
46
  start = time.time()
47
- for i in range(100):
48
  test_image()
49
  end = time.time()
50
- # print average time in seconds and in milliseconds
51
- print("Average time for image: ", (end - start) / 100, "s")
52
- print("Average time for image: ", (end - start) * 10, "ms")
53
- print("Number of predictions per second for image: ", 1 / ((end - start) / 100))
54
 
55
 
56
 
@@ -72,11 +73,11 @@ payload = encode_numpy_array(input_image)
72
 
73
  # performance test for image as payload
74
  start = time.time()
75
- for i in range(100):
76
  test_image_as_payload(payload)
77
  end = time.time()
78
- # print average time in seconds and in milliseconds
79
- print("Average time for image as payload: ", (end - start) / 100, "s")
80
- print("Average time for image as payload: ", (end - start) * 10, "ms")
81
- print("Number of predictions per second for image as payload: ", 1 / ((end - start) / 100))
82
 
 
6
 
7
  from api_helper import preprocess_image, encode_numpy_array
8
  clip_image_size = 224
9
+ num_steps = 1000
10
 
11
  client = Client("http://127.0.0.1:7860/")
12
 
 
35
 
36
  # performance test for text
37
  start = time.time()
38
+ for i in range(num_steps):
39
  test_text()
40
  end = time.time()
41
+ average_time_seconds = (end - start) / num_steps
42
+ print("Average time for text: ", average_time_seconds, "s")
43
+ print("Average time for text: ", average_time_seconds * 1000, "ms")
44
+ print("Number of predictions per second for text: ", 1 / average_time_seconds)
45
 
46
  # performance test for image
47
  start = time.time()
48
+ for i in range(num_steps):
49
  test_image()
50
  end = time.time()
51
+ average_time_seconds = (end - start) / num_steps
52
+ print("Average time for image: ", average_time_seconds, "s")
53
+ print("Average time for image: ", average_time_seconds * 1000, "ms")
54
+ print("Number of predictions per second for image: ", 1 / average_time_seconds)
55
 
56
 
57
 
 
73
 
74
  # performance test for image as payload
75
  start = time.time()
76
+ for i in range(num_steps):
77
  test_image_as_payload(payload)
78
  end = time.time()
79
+ average_time_seconds = (end - start) / num_steps
80
+ print("Average time for image as payload: ", average_time_seconds, "s")
81
+ print("Average time for image as payload: ", average_time_seconds * 1000, "ms")
82
+ print("Number of predictions per second for image as payload: ", 1 / average_time_seconds)
83