blob: 8e5a0b4b10141c04f1eb685b580d8deeb57abd76 [file] [log] [blame]
Andrew Yourtchenkofa1456a2016-11-11 16:32:52 +00001--[[
2/*
3 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16]]
17
18local vpp = require "vpp-lapi"
19
20local ffi = require "ffi"
21
22ffi.cdef([[
23 struct timespec {
24 long tv_sec; /* seconds */
25 long tv_nsec; /* nanoseconds */
26 };
27
28 int clock_gettime(int clk_id, struct timespec *tp);
29]])
30
31
32local time_cache = ffi.new("struct timespec[1]")
33local time_cache_1 = time_cache[0]
34function get_ns()
35 ffi.C.clock_gettime(0, time_cache)
36 return time_cache_1.tv_nsec + 1000000000 * time_cache_1.tv_sec
37end
38
39function do_bench()
40 local cycle_start = get_ns()
41 local n_iterations = 10000
42 local count = 1
43 for i = 1,n_iterations do
44 -- print(i)
45 vpp:api_call("show_version")
46 count = count + 1
47 -- print(i, "done")
48 end
49 cycle_end = get_ns()
50 local tps = n_iterations*1000000000LL/(cycle_end - cycle_start)
51 print (tostring(count) .. " iterations, average speed " .. tostring(tps) .. " per second")
52 return tps
53end
54
55root_dir = "/home/ubuntu/vpp"
Andrew Yourtchenkob868e4e2016-12-08 14:03:55 +000056pneum_path = root_dir .. "/build-root/install-vpp_lite_debug-native/vpp-api/lib64/libpneum.so"
Andrew Yourtchenkofa1456a2016-11-11 16:32:52 +000057vpp:init({ pneum_path = pneum_path })
Andrew Yourtchenkob868e4e2016-12-08 14:03:55 +000058vpp:json_api(root_dir .. "/build-root/install-vpp_lite_debug-native/vpp/vpp-api/vpe.api.json")
Andrew Yourtchenkofa1456a2016-11-11 16:32:52 +000059
60vpp:connect("lua-bench")
61local n_tests = 10
62local tps_acc = 0LL
63for i=1,n_tests do
64 tps_acc = tps_acc + do_bench()
65end
66print("Average tps across the tests: " .. tostring(tps_acc/n_tests))
67
68vpp:disconnect()
69
70