Skip to content

Commit

Permalink
Print out nanseconds by byte and per csum
Browse files Browse the repository at this point in the history
  • Loading branch information
dpino committed Apr 25, 2018
1 parent 6f12e3b commit 311196c
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/lib/newchecksum.dasl
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,15 @@ function selftest ()
end
local function benchmark (fn, times)
local now = os.clock()
local temp
local csum
for i=1,times do
temp = fn()
csum, pkt = fn()
end
local ret = {os.clock() - now, temp}
return ret[1]
local elapse = os.clock() - now
local ns_per_byte = elapse * 10e9 / pkt.length
local ns_per_csum = elapse * 10e9 / times
local ret = {elapse = elapse, ns_per_byte = ns_per_byte, ns_per_csum = ns_per_csum, csum = csum}
return ("elapse: %.6f; ns_per_byte: %.2f; ns_per_csum: %.2f"):format(ret.elapse, ret.ns_per_byte, ret.ns_per_csum)
end
local function hex (num)
return ("0x%.2x"):format(num)
Expand All @@ -167,10 +170,10 @@ function selftest ()
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(ntohs(checksum_lua(pkt.data, pkt.length))))
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(C.cksum_generic(pkt.data, pkt.length, 0)))
-- Benchmark for different architectures.
print("Gen: ", benchmark(function() return C.cksum_generic(pkt.data, pkt.length, 0) end, times))
print("SSE2: ", benchmark(function() return C.cksum_sse2(pkt.data, pkt.length, 0) end, times))
print("AVX2: ", benchmark(function() return C.cksum_avx2(pkt.data, pkt.length, 0) end, times))
print("New: ", benchmark(function() return newchecksum(pkt.data, pkt.length) end, times))
print("Gen: ", benchmark(function() return C.cksum_generic(pkt.data, pkt.length, 0), pkt end, times))
print("SSE2: ", benchmark(function() return C.cksum_sse2(pkt.data, pkt.length, 0), pkt end, times))
print("AVX2: ", benchmark(function() return C.cksum_avx2(pkt.data, pkt.length, 0), pkt end, times))
print("New: ", benchmark(function() return newchecksum(pkt.data, pkt.length), pkt end, times))

size = 550
print("2M; "..size.." bytes")
Expand All @@ -180,10 +183,10 @@ function selftest ()
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(ntohs(checksum_lua(pkt.data, pkt.length))))
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(C.cksum_generic(pkt.data, pkt.length, 0)))
-- Benchmark for different architectures.
print("Gen: ", benchmark(function() return C.cksum_generic(pkt.data, pkt.length, 0) end, times))
print("SSE2: ", benchmark(function() return C.cksum_sse2(pkt.data, pkt.length, 0) end, times))
print("AVX2: ", benchmark(function() return C.cksum_avx2(pkt.data, pkt.length, 0) end, times))
print("New: ", benchmark(function() return newchecksum(pkt.data, pkt.length) end, times))
print("Gen: ", benchmark(function() return C.cksum_generic(pkt.data, pkt.length, 0), pkt end, times))
print("SSE2: ", benchmark(function() return C.cksum_sse2(pkt.data, pkt.length, 0), pkt end, times))
print("AVX2: ", benchmark(function() return C.cksum_avx2(pkt.data, pkt.length, 0), pkt end, times))
print("New: ", benchmark(function() return newchecksum(pkt.data, pkt.length), pkt end, times))

size = 1500
print("1M; "..size.." bytes")
Expand All @@ -193,8 +196,8 @@ function selftest ()
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(ntohs(checksum_lua(pkt.data, pkt.length))))
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(C.cksum_generic(pkt.data, pkt.length, 0)))
-- Benchmark for different architectures.
print("Gen: ", benchmark(function() return C.cksum_generic(pkt.data, pkt.length, 0) end, times))
print("SSE2: ", benchmark(function() return C.cksum_sse2(pkt.data, pkt.length, 0) end, times))
print("AVX2: ", benchmark(function() return C.cksum_avx2(pkt.data, pkt.length, 0) end, times))
print("New: ", benchmark(function() return newchecksum(pkt.data, pkt.length) end, times))
print("Gen: ", benchmark(function() return C.cksum_generic(pkt.data, pkt.length, 0), pkt end, times))
print("SSE2: ", benchmark(function() return C.cksum_sse2(pkt.data, pkt.length, 0), pkt end, times))
print("AVX2: ", benchmark(function() return C.cksum_avx2(pkt.data, pkt.length, 0), pkt end, times))
print("New: ", benchmark(function() return newchecksum(pkt.data, pkt.length), pkt end, times))
end

0 comments on commit 311196c

Please sign in to comment.