Repair Doxygen build infrastructure
[vpp.git] / src / vpp-api / lua / bench.lua
1 --[[
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
18 local vpp = require "vpp-lapi"
19
20 local ffi = require "ffi"
21
22 ffi.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
32 local time_cache = ffi.new("struct timespec[1]")
33 local time_cache_1 = time_cache[0]
34 function get_ns()
35   ffi.C.clock_gettime(0, time_cache)
36   return time_cache_1.tv_nsec + 1000000000 * time_cache_1.tv_sec
37 end
38
39 function 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
53 end
54
55 root_dir = "/home/ubuntu/vpp"
56 pneum_path = root_dir .. "/build-root/install-vpp_lite_debug-native/vpp-api/lib64/libpneum.so"
57 vpp:init({ pneum_path = pneum_path })
58 vpp:json_api(root_dir .. "/build-root/install-vpp_lite_debug-native/vpp/vpp-api/vpe.api.json")
59
60 vpp:connect("lua-bench")
61 local n_tests = 10
62 local tps_acc = 0LL
63 for i=1,n_tests do
64   tps_acc = tps_acc + do_bench()
65 end
66 print("Average tps across the tests: " .. tostring(tps_acc/n_tests))
67
68 vpp:disconnect()
69
70