Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Further optimize the module #2

Open
howmanysmall opened this issue Nov 4, 2019 · 4 comments
Open

Further optimize the module #2

howmanysmall opened this issue Nov 4, 2019 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@howmanysmall
Copy link
Owner

There's a few things that could be done to make it faster.

For one, the Base64 system probably isn't up to standards. It can be replaced with the FastestBase64 module I have on my gist.

Another thing that can be done to increase the speed is to reduce function calls as much as possible. I'm fairly sure that this is the reason this module is so much faster. This of course would take a lot of time and energy to do alone, so this will most likely be a thing I do over time.

@howmanysmall howmanysmall added enhancement New feature or request help wanted Extra attention is needed labels Nov 4, 2019
@LoganDark
Copy link

LoganDark commented Mar 9, 2022

reduce function calls as much as possible

There's already a couple instances of % 1 == 0 which is actually slightly slower than math.floor

image

local n = 10000

return {
	ParameterGenerator = function()
		if math.random(1, 2) == 1 then
			return math.random() * 1000 -- float
		else
			return math.random(1, 1000) -- integer
		end
	end,

	Functions = {
		['math.floor'] = function(profiler: Profiler, number: number)
			for i = 1, n do
				if math.floor(number) == number then end
			end
		end,

		['%'] = function(profiler: Profiler, number: number)
			for i = 1, n do
				if number % 1 == 0 then end
			end
		end,

		['frexp'] = function(profiler: Profiler, number: number)
			for i = 1, n do
				local _, e = math.frexp(number)
				if e == 1 then end
			end
		end,

		['frexp + select'] = function(profiler: Profiler, number: number)
			for i = 1, n do
				if select(2, math.frexp(number)) == 1 then end
			end
		end
	}
}

@howmanysmall
Copy link
Owner Author

Don't use this please. This was written a long time ago.

Use this one

@howmanysmall
Copy link
Owner Author

Good find though!

@LoganDark
Copy link

LoganDark commented Mar 9, 2022

Don't use this please.

I have no need for it anyway, I find all the bitbuffer libraries kind of laughable because everyone tends to write one (usually just modify stravant's) when they're just starting out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants