Giter Club home page Giter Club logo

Comments (8)

TheBeardedQuack avatar TheBeardedQuack commented on September 27, 2024 1

from async-sockets-cpp.

Not-Nik avatar Not-Nik commented on September 27, 2024 1

Fair point and of course: your library, your call, but still; we got a decrease of average 30 ms per 1 million calls. That's 0.00003 milliseconds per call, so really nothing you should worry about.

from async-sockets-cpp.

eminfedar avatar eminfedar commented on September 27, 2024 1

It is open source and of course I can be wrong no problem :) (that's the point of the open source, a community which powers the other's lacks)

Actually you guys have convinced me using std::function is not a "big performance killer".

Having this type of flexibility while having only just a few amount of performance drop is a fair exchange :)

from async-sockets-cpp.

TheBeardedQuack avatar TheBeardedQuack commented on September 27, 2024

Do you have proof of this? You should measure performance metrics before optimising.

from async-sockets-cpp.

eminfedar avatar eminfedar commented on September 27, 2024

For example:
Here is the two equal functions:

int i = 0;
std::function<void()> a = [&] {
    i++;
};

auto b = [&]{
    i++;
};

Then if I run them in a 1 million for loop like this:

int k;
for (k = 0; k < 1000000; k++){
    a();
    // b();
}

And measure the time with time ./a.out command results:

# Compiled with a() (std::function)
eminfedar@mi:~/Documents/C/functiontest$ time ./a.out 

real    0m0.052s
user    0m0.052s
sys     0m0.001s
eminfedar@mi:~/Documents/C/functiontest$ time ./a.out 

real    0m0.030s
user    0m0.029s
sys     0m0.001s
eminfedar@mi:~/Documents/C/functiontest$ time ./a.out 

real    0m0.051s
user    0m0.051s
sys     0m0.001s

# Compile again with other b(); (normal lamda function)
eminfedar@mi:~/Documents/C/functiontest$ g++ main.cpp -std=c++11
eminfedar@mi:~/Documents/C/functiontest$ time ./a.out 

real    0m0.015s
user    0m0.011s
sys     0m0.004s
eminfedar@mi:~/Documents/C/functiontest$ time ./a.out 

real    0m0.009s
user    0m0.004s
sys     0m0.005s
eminfedar@mi:~/Documents/C/functiontest$ time ./a.out 

real    0m0.008s
user    0m0.004s
sys     0m0.004s

It seems 4-5 times slower.

from async-sockets-cpp.

eminfedar avatar eminfedar commented on September 27, 2024

Yes actually std::function is very easy to use. But I'm just considering can we make this better while not making ugly. I have tried template Functor once but it didn't work as expected as you said. Lot of flexibility gone.

Of course it is not changing for now.

But if I find a better way ... :)

from async-sockets-cpp.

Not-Nik avatar Not-Nik commented on September 27, 2024

As TheBeardedQuack pointed out, your test isn't really proving anything in regards to execution speed. std::function indeed slows down the startup of a function, simply because there is at least one additional function call involved compared to a normal function, but the actual execution time of a function stays the same. That being said, on your given system the performs cost of using std::function is more or less always the same 20 - 40 ms, and won't increase with the complexity of the called function.

from async-sockets-cpp.

eminfedar avatar eminfedar commented on September 27, 2024

Think about it. you are developing a game server for example with this udp library and you want to have least latency. Think about it on thousands of users sending kilobytes of data and of course your handling function is not "i++".

I'm thinking about "max performance, least latency", because we are using C++, so: "performance" :)

Yes actualy function execution time doesn't change. I'm considering about latency here.

from async-sockets-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.