From a600abfa5813d740dbb051f89f65a03a765441ea Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 25 Apr 2016 17:12:22 +0100 Subject: [Test] Add speed test for addr parser --- test/lua/unit/smtp_addr.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/lua/unit/smtp_addr.lua b/test/lua/unit/smtp_addr.lua index efd6cda8f..efac3a2af 100644 --- a/test/lua/unit/smtp_addr.lua +++ b/test/lua/unit/smtp_addr.lua @@ -3,6 +3,7 @@ context("SMTP address check functions", function() local logger = require("rspamd_logger") local ffi = require("ffi") + local util = require("rspamd_util") require "fun" () ffi.cdef[[ struct rspamd_email_address { @@ -27,6 +28,13 @@ context("SMTP address check functions", function() local cases_valid = { {'<>', {addr = ''}}, {'', {user = 'a', domain = 'example.com', addr = 'a@example.com'}}, + {'', {user = 'a-b', domain = 'example.com', addr = 'a-b@example.com'}}, + {'', {user = 'a-b', domain = 'ex-ample.com', addr = 'a-b@ex-ample.com'}}, + {'1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru', + {user = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370', + domain = 'example.220-volt.ru', + addr = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru'}}, + {'notification+kjdm---m7wwd@facebookmail.com', {user = 'notification+kjdm---m7wwd'}}, {'a@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}}, {'a+b@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}}, {'"a"@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}}, @@ -79,4 +87,20 @@ context("SMTP address check functions", function() assert_nil(st, "should not be able to parse " .. case) end, cases_invalid) end) + test("Speed test", function() + local case = '<@domain1,@domain2,@domain3:abc%d@example.com>' + local niter = 100000 + local total = 0 + + for i = 1,niter do + local ncase = string.format(case, i) + local t1 = util.get_ticks() + local st = ffi.C.rspamd_email_address_from_smtp(ncase, #ncase) + local t2 = util.get_ticks() + ffi.C.rspamd_email_address_unref(st) + total = total + t2 - t1 + end + + print(string.format('Spend %f seconds in processing addrs', total)) + end) end) -- cgit v1.2.3