Skip to content

Instantly share code, notes, and snippets.

@RunsFor
Last active November 20, 2024 17:37
Show Gist options
  • Save RunsFor/edda7ee0528756acb632bc74131c8a7b to your computer and use it in GitHub Desktop.
Save RunsFor/edda7ee0528756acb632bc74131c8a7b to your computer and use it in GitHub Desktop.
box.insert with exception performance
local clock = require('clock')
box.cfg{}
box.schema.create_space('test', {if_not_exists = true})
box.space.test:create_index('pk', {if_not_exists = true})
local fiber = require('fiber')
fiber.set_max_slice({warn = 2, err = 5})
local function test1()
for _ = 1, 10000 do
pcall(box.space.test.insert, box.space.test, {1})
end
end
local function test2()
for _ = 1, 10000 do
if not box.space.test:get(1) then
box.space.test.insert({1})
end
end
end
local function test3()
for _ = 1, 10000 do
pcall(error, 'yes')
end
end
local t1 = clock.time()
test1()
local t2 = clock.time()
test2()
local t3 = clock.time()
test3()
local t4 = clock.time()
print("test_1: ", t2 - t1)
print("test_2: ", t3 - t2)
print("test_3: ", t4 - t3)
$ tarantool main.lua
...
test_1: 1.2289569377899
test_2: 0.037437915802002
test_3: 1.1791739463806
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment