Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>,
	Roman Khabibov <roman.habibov@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] serializer: serialize recursive structures
Date: Wed, 21 Apr 2021 16:12:58 +0300	[thread overview]
Message-ID: <092bc107-40cd-2c58-7a90-236663551249@tarantool.org> (raw)
In-Reply-To: <YH/v+lCWCryrRo58@root>


On 21.04.2021 12:27, Sergey Kaplun via Tarantool-patches wrote:
> Hi!
>
> Thanks for the fixes and the benchmarks!

I propose an updated version of script and propose to add benchmark as a 
part of patch series.

--[[
-- measure serialization time
-- run: taskset -c 1 tarantool perf.lua
]]

local clock = require('clock')

local function elapsed(f, n)
     local t0 = clock.monotonic()
     for i = 1, n do
         f()
     end
     local t1 = clock.monotonic()
     return t1 - t0
end

-- Get the mean of a table
function calculate_mean(t)
   local sum = 0
   local count= 0
   for k, v in pairs(t) do
     if type(v) == 'number' then
       sum = sum + v
     end
   end

   return (sum/#t)
end

-- Get the median of a table.
function calculate_median(t)
   local temp = {}
   -- deep copy table so that when we sort it, the original is unchanged
   -- also weed out any non numbers
   for k, v in pairs(t) do
     if type(v) == 'number' then
       table.insert(temp, v)
     end
   end
   table.sort(temp)
   -- If we have an even number of table elements or odd.
   if math.fmod(#temp,2) == 0 then
     -- return mean value of middle two elements
     return (temp[#temp/2] + temp[(#temp/2)+1]) / 2
   else
     -- return middle element
     return temp[math.ceil(#temp/2)]
   end
end

-- Get the standard deviation of a table
function calculate_stddev(t)
   local vm
   local sum = 0
   local mean = calculate_mean(t)
   for k, v in pairs(t) do
     if type(v) == 'number' then
       vm = v - mean
       sum = sum + (vm * vm)
     end
   end

   return math.sqrt(sum/(#t - 1))
end

local function timeit(f, name)
     print('======================================')
     print(name)
     print('======================================')
     local res = {}
     local iterations = 10
     local elapsed_time = 0
     local repetitions = 150000
     for j = 1, iterations do
         -- warming
         for i = 1, 100 do f() end
         -- measurement
         elapsed_time = elapsed(f, repetitions)
         table.insert(res, elapsed_time)
         print(string.format("%-2d - %f sec / %d repetitions", j, 
elapsed_time, repetitions))
     end
     print(string.format("time mean   %f", calculate_mean(res)))
     print(string.format("time median %f", calculate_median(res)))
     print(string.format("time stddev %f", calculate_stddev(res)))
end

local t = {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
timeit(function()
            local console = require('console')
            console.set_default_output('yaml')
            return console.eval(tostring(t))
        end, 'serializer console yaml')
timeit(function()
            local console = require('console')
            console.set_default_output('lua')
            return console.eval(tostring(t))
        end, 'serializer console lua')
timeit(function()
            local serializer = require('json')
            serializer.cfg({encode_max_depth = 64})
            return serializer.encode(t)
        end, 'serializer json')
timeit(function()
            local serializer = require('yaml')
            serializer.cfg({encode_max_depth = 64})
            return serializer.encode(t)
        end, 'serializer yaml')
timeit(function()
            local serializer = require('msgpack')
            serializer.cfg({encode_max_depth = 64})
            return serializer.encode(t)
        end, 'serializer msgpack')
timeit(function()
            local serializer = require('msgpackffi')
            return serializer.encode(t)
        end, 'serializer msgpackffi')


  reply	other threads:[~2021-04-21 13:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11  5:49 Roman Khabibov via Tarantool-patches
2021-03-14 12:42 ` Sergey Kaplun via Tarantool-patches
2021-04-05 22:05   ` Roman Khabibov via Tarantool-patches
2021-04-21  9:27     ` Sergey Kaplun via Tarantool-patches
2021-04-21 13:12       ` Sergey Bronnikov via Tarantool-patches [this message]
2021-04-21 18:20         ` Sergey Kaplun via Tarantool-patches
2021-04-13 15:54 ` Sergey Bronnikov via Tarantool-patches
2021-04-15 20:39   ` Roman Khabibov via Tarantool-patches
2021-04-21 12:34 ` Sergey Bronnikov via Tarantool-patches
2021-07-07 22:42 ` Alexander Turenko via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=092bc107-40cd-2c58-7a90-236663551249@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=roman.habibov@tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] serializer: serialize recursive structures' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox