Take advantage of Multi-Core Processors and Multi-threading
Posts 1–15 of 15 · Page 1 of 1
Take advantage of Multi-Core Processors and Multi-threading
MultiThreading is already in the programs u develop, just behind the scenes. Take advantage of it to improve the performance of those multi-core processors and optimize it for the single thread processors.
This will allow u to do multiple things at a time using multiple threads.The number of threads are limited to the number of logical processor and single thread processors will not see any performance change. Something like this will help u with your menus. The reason menus lag is because of the font. Having to draw every character in every string for every item. For each character in a string, in each items, that is a lot of time wasted in looping, but what if u could do more than one of these at a time.
Example:
Please note that fonts not coded for concurrency may have rendering errors, if requested i will be willing to code a Font class for Concurrency
Code:
//This function will return the time it takes to call the function
template <class Function>
__int64 time_call(Function&& f){
__int64 begin = GetTickCount();
f();
return GetTickCount() - begin;
}
void DrawParallel()
{
parallel_for(0, 10, [&] (int i)
{
Font.DrawText(200, 20+ i*15, WHITE, "BLA BLA BLA");
});
}
void DrawSerial()
{
for(int i = 0; i < 10; i++)
{
Font.DrawText(20 , 20 + i*15, WHITE, "BLA BLA BLA");
}
}
void RenderFont()
{
// Draws the time it takes to do these different Draws.
Font.DrawNumber( 200, 10, WHITE, time_call([&] { DrawParallel(); } ));
Font.DrawNumber( 20, 10, WHITE, time_call([&] { DrawSerial(); } ));
}
Depending on the number of logical cores the time it takes to render these times may differ.
little info for beginners, how it works(shown in screenshots):
the code(tip: there is a namespace, but you should already figured it out)
first run
second run
you should see it. result is based on a dual core, 2.2GHz
ignore title of project, was a demo for my classmates lol
yes, it doesnt run things one after the other, but a random number can be picked to run in the threads
Because of this limits of 2 cores (guessing u have 2 threads), some threads are used again to process the information, so it Serializing in the parallel threads.
Running this code to time it and Sleep for 10 ms i got the times below, u can see the difference 8 threaded processor have over the 4 threaded one when using parallelism.
Running this code to time it and Sleep for 10 ms i got the times below, there is no difference between the 8 threaded processor and the 4 threaded one when using traditional for loops, performance wasted.
---------- Post added at 11:05 PM ---------- Previous post was at 10:53 PM ---------- Test for AMD Phenom II x4 (Quad Core, 4 Thread) = 125 ms vs 499ms
---------- Post added at 11:09 PM ---------- Previous post was at 11:05 PM ----------
Test for Intel CORE i7 sandybridge (Quad Core x2 threads, 8 Threads ) = 62ms ~ 78 ms vs 499ms
: This is why Intel Better, more threads in a core, so 8 logical processors, just saying
race me to 3000
Intel i5 760 @2.8ghz
Originally Posted by matypatty
race me to 3000
Intel i5 760 @2.8ghz
you have the biggest penis. gratz.
Originally Posted by kotentopf
you have the biggest penis. gratz.
He really Does.
Originally Posted by abathx
He really Does.
could we now stop share penis size?
Originally Posted by topblast
MultiThreading is already in the programs u develop, just behind the scenes. Take advantage of it to improve the performance of those multi-core processors and optimize it for the single thread processors.
This will allow u to do multiple things at a time using multiple threads.The number of threads are limited to the number of logical processor and single thread processors will not see any performance change. Something like this will help u with your menus. The reason menus lag is because of the font. Having to draw every character in every string for every item. For each character in a string, in each items, that is a lot of time wasted in looping, but what if u could do more than one of these at a time.
Example:
Please note that fonts not coded for concurrency may have rendering errors, if requested i will be willing to code a Font class for Concurrency
Code:
//This function will return the time it takes to call the function
template <class Function>
__int64 time_call(Function&& f){
__int64 begin = GetTickCount();
f();
return GetTickCount() - begin;
}
void DrawParallel()
{
parallel_for(0, 10, [&] (int i)
{
Font.DrawText(200, 20+ i*15, WHITE, "BLA BLA BLA");
});
}
void DrawSerial()
{
for(int i = 0; i < 10; i++)
{
Font.DrawText(20 , 20 + i*15, WHITE, "BLA BLA BLA");
}
}
void RenderFont()
{
// Draws the time it takes to do these different Draws.
Font.DrawNumber( 200, 10, WHITE, time_call([&] { DrawParallel(); } ));
Font.DrawNumber( 20, 10, WHITE, time_call([&] { DrawSerial(); } ));
}
Depending on the number of logical cores the time it takes to render these times may differ.
Don't be shit, blit!
Originally Posted by Jason
Don't be shit, blit!
I dont comprehend
---------- Post added at 11:31 PM ---------- Previous post was at 11:29 PM ----------
Originally Posted by kotentopf
you have the biggest penis. gratz.
Mines bigger, that plus i am black
Originally Posted by topblast
I dont comprehend
Of course you don't, which is why you're using parallelism as a crutch for crap DX code.
Originally Posted by Jason
Of course you don't, which is why you're using parallelism as a crutch for crap DX code.
i am using for the stuff that lags the most in these hacks and pretty much, If i can help educate the people in this section I take it for that.
Originally Posted by topblast
i am using for the stuff that lags the most in these hacks and pretty much, If i can help educate the people in this section I take it for that.
You're avoiding the problem, not addressing it. Anyways, we've had this discussion before so there's no need to rehash it but even with my extremely limited knowledge of directX, I can see lots of better ways to improve menu efficiency rather than just taking a "fuck it, computers are powerful, I don't need to code well" approach.
Off-screen surfaces,
Blitting,
Rendering to the backbuffer.
Google any, or a combination of these and you'll see what I'm talking about. A huge portion of the menu never changes, and when it does it's usually in response to user input. There's no need to redraw the menu piece-by-piece every time present/endscene is called. Simply draw it to an offscreen surface once and blit it to the display when needed. When the user provides some input, you can just redraw the offending parts on the offscreen surface (or the whole menu if need be). Far less unnecessary overhead and calls to performancing-hitting functions like DrawText.
As I said, I have only a limited knowledge of DX, there are probably dozens of ways to further improve efficiency.
Originally Posted by Jason
You're avoiding the problem, not addressing it. Anyways, we've had this discussion before so there's no need to rehash it but even with my extremely limited knowledge of directX, I can see lots of better ways to improve menu efficiency rather than just taking a "fuck it, computers are powerful, I don't need to code well" approach.
Off-screen surfaces,
Blitting,
Rendering to the backbuffer.
Google any, or a combination of these and you'll see what I'm talking about. A huge portion of the menu never changes, and when it does it's usually in response to user input. There's no need to redraw the menu piece-by-piece every time present/endscene is called. Simply draw it to an offscreen surface once and blit it to the display when needed. When the user provides some input, you can just redraw the offending parts on the offscreen surface (or the whole menu if need be). Far less unnecessary overhead and calls to performancing-hitting functions like DrawText.
As I said, I have only a limited knowledge of DX, there are probably dozens of ways to further improve efficiency.
my sites are approach have change, the thing is I already optimized the DX functions as much as my current knowledge can take me. now i am optimizing it be putting speed into the memory manipulation.
Also it will be more work than anything to be checking to see if the menu change also many functions of the menus requires the part that people don't see.
The part i am really trying to optimize is the filling of the vertices for the font.
while (*strText++)
as it adds one character to the vertexbuffer. this part is not really d3d its filling an array, a large array.