Comments (3)
The benchmark below shows a very minimal improvement, however the execution time of the square root calculation ultimately depends on the input given.
local benchmark
local vec = VectorRand() * 1000
local getLength = vec.Length
local getLengthSqr = vec.LengthSqr
print("Benchmark data : ", vec, "\n")
do
benchmark = SysTime()
for i = 1, 2e5 do end
print("Baseline : ", SysTime() - benchmark)
end
do
benchmark = SysTime()
for i = 1, 2e5 do
getLength(vec)
end
print("Vector:Length() : ", SysTime() - benchmark)
end
do
benchmark = SysTime()
for i = 1, 2e5 do
getLengthSqr(vec)
end
print("Vector:LengthSqr() : ", SysTime() - benchmark)
end
print("\n")
Results (after 5 runs):
Benchmark data : 495.429901 739.004211 436.868652
Baseline : 9.6400000074937e-05
Vector:Length() : 0.0059317999998711
Vector:LengthSqr() : 0.0055161000000226
Benchmark data : -522.012939 -765.965698 -75.552155
Baseline : 8.6899999814705e-05
Vector:Length() : 0.0058865999999398
Vector:LengthSqr() : 0.0055757000000085
Benchmark data : 256.878876 818.915649 -309.296326
Baseline : 0.0001259000000573
Vector:Length() : 0.0059771999999612
Vector:LengthSqr() : 0.0057152000001679
Benchmark data : 375.659027 -366.963501 -569.133728
Baseline : 9.0699999873323e-05
Vector:Length() : 0.0060378999999102
Vector:LengthSqr() : 0.0056388000000425
Benchmark data : -381.458496 -671.425659 715.860413
Baseline : 8.87999999577e-05
Vector:Length() : 0.0059182999998484
Vector:LengthSqr() : 0.0056335000001582
from imgui.
Can you (or anyone) provide a benchmark proving that it would be more efficient?
Squared distance being so much more efficient than normal distance that it should be changed everywhere is probably the biggest misunderstanding around gmod devs. I wouldn't necessarily be against changing it here if done properly, since it wouldn't affect code complexity that much, but oh boy does everyone like suggesting this "optimization" without actually testing if it has any impact first.
from imgui.
Thanks! So ~5% improvement (or very roughly 10000th of a millisecond per call).
I wouldn't mind the change here, since it's very localized and requires only two lines changed. It is quite a micro-optimization, however. I guess crossing the C++ boundary is the source of slowness here.
from imgui.
Related Issues (20)
- Buttons wont work HOT 11
- Network Send HOT 3
- Ran into a Problem HOT 1
- Many scenes | I need help HOT 2
- Imgui End Problems HOT 8
- Lost how how to get it working ;3; HOT 2
- Error when fade out HOT 4
- Insert image in 3D2D HOT 4
- Use IN enumerations instead of input
- Why is imgui bugging if another condition is in the if (imgui.Entity3D2D(self, Vector(-71, -95, 2), Angle(0, 90, 0), 0.1)) then HOT 4
- Errorless CTD on physgun interactions and re-entering render range HOT 2
- Can you do this? HOT 1
- ImGUI on viewmodel doesn't properly find cursor position HOT 3
- FOV causing out of sync cursor HOT 3
- Pressing a button in :Draw presses it twice HOT 1
- How to migrate from tdui? HOT 2
- Render different stuff HOT 2
- Highlight entity when using Entity3D2D and in debug mode
- How to rotate TextButton and text ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgui.