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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 local vpp = require "vpp-lapi"
20 local ffi = require "ffi"
24 long tv_sec; /* seconds */
25 long tv_nsec; /* nanoseconds */
28 int clock_gettime(int clk_id, struct timespec *tp);
32 local time_cache = ffi.new("struct timespec[1]")
33 local time_cache_1 = time_cache[0]
35 ffi.C.clock_gettime(0, time_cache)
36 return time_cache_1.tv_nsec + 1000000000 * time_cache_1.tv_sec
40 local cycle_start = get_ns()
41 local n_iterations = 10000
43 for i = 1,n_iterations do
45 vpp:api_call("show_version")
50 local tps = n_iterations*1000000000LL/(cycle_end - cycle_start)
51 print (tostring(count) .. " iterations, average speed " .. tostring(tps) .. " per second")
55 root_dir = "/home/ubuntu/vpp"
56 pneum_path = root_dir .. "/build-root/install-vpp_debug-native/vpp-api/lib64/libpneum.so"
57 vpp:init({ pneum_path = pneum_path })
58 vpp:json_api(root_dir .. "/build-root/install-vpp_debug-native/vpp/vpp-api/vpe.api.json")
60 vpp:connect("lua-bench")
64 tps_acc = tps_acc + do_bench()
66 print("Average tps across the tests: " .. tostring(tps_acc/n_tests))