[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Metatable check helper API proposal
- From: 云风 Cloud Wu <cloudwu@...>
- Date: Thu, 20 Aug 2020 11:33:17 +0800
云风 Cloud Wu <cloudwu@gmail.com> 于2020年8月20日周四 上午10:57写道:
> ```lua
> local N = 100000000
>
> local a = {}
> local meta = {} ; meta.__index = meta
>
> function meta:foo()
> end
>
> setmetatable(a, meta)
>
> local t = os.clock()
>
> for i = 1, N do
> local foo = a.foo
> end
>
> local t1 = os.clock()
>
> for i = 1, N do
> local foo = a:foo()
> end
>
> local t2 = os.clock()
>
> print(t1 - t, t2 - t1)
> ```
>
> Intel i7-7700 @ 3.60GHz Windows 10 mingw64 gcc 8.2.0
>
> lua 5.4 (https://github.com/lua/lua master) 1.524 2.887
> After patch (See attachment): 1.271 2.492
I added the empty loop test.
local N = 100000000
local a = {}
local meta = {} ; meta.__index = meta
function meta:foo()
end
setmetatable(a, meta)
local t = os.clock()
for i = 1, N do
local foo = a.foo
end
local t1 = os.clock()
for i = 1, N do
local foo = a:foo()
end
local t2 = os.clock()
for i = 1, N do
local foo = a
end
local t3 = os.clock()
print(t1 - t, t2 - t1, t3 - t2)
```
Intel i7-7700 @ 3.60GHz Windows 10 mingw64 gcc 8.2.0
lua 5.4 1.551 2.807 0.378
After patch 1.259 2.593 0.378
(1.551-0.378) / (1.259-0.378) = 1.331
I think it's 33% faster.
--
http://blog.codingnow.com