When you started this series, I thought I had a decent enough understanding of C++ and didn't need to watch it. I've watched episodes anyway because I enjoy your video style. I've learned so much though. For example, I knew about std::chrono and some profiling methods before watching this, but I've never seen anyone wrap it so nicely in an object and use scope lifetime to their advantage so well. I'll make use of this from now on. So many great tricks to pick up from watching this series! Thanks as always Cherno! :)
In cygwin I had to use _std::chrono::high_resolution_clock::time_point_ instead of _std::chrono::time_point_ Just an FYI for anyone getting the error that there is no _'operator='_ on std::chorno::time_point you may want to try the high resolution one.
Another great video, love that you're using RAII, it's really the best c++ feature. btw you could have used "std::chrono::duration_cast" for your ms conversion ;)
@@them4309 Would have to be a pretty long report to be fair. I would imagine the report would be written to file though as logging it is probably super important.
those who are facing issue with chrono::time_point should use chrono::time_point....I think this issue is due to difference in OS( I have linux mint,cherno is using windows)..
Or you can just change to use the high_resolution_clock as the templated type given to the time_point constructor. Then the now() methods are returning the same type as the time_point objects (start, end) are expecting. For added fun, I suppose you could also try to cast the steady_clock object to a high_resolution_clock object, and see if that works...lol. Talk about ugly syntax!
me: *seeing a C++ tutorial* me: *opening this tutorial* cherno's video: *appears* me: *without watching to the end instantly clicking on cherno's video*
hey, im a beginner to c++ and when I try to use the chrono, i keep getting an error that it cant be resolved. I check my version of gcc and its up to date so I have no idea what the issue it. Does anyone know what I could do here?
Hi Cherno ... I have idea, right click name project and click Properties -> Linker -> System -> SubSystem ... choose Console and OK then your console will stop without infinite loop, etc ...
Yan Chernikov ! My C++ Mentor !! I Learned And Mastered Pointers (* = raw) with your help because these stars thing are too annoying. Love From Pakistan
You could also manually time functions in your code to see how quick they perform by passing a function pointer to the function that will time it. Example: void time_this() { for(int i = 0; i < 10000; i++) { std::cout
As always awesome video, love em all ! I know its some deep stuff but do you have any plans to cover the SIMD (single instruction multiple data ) instruction set ? Keep up the good work !
std::endl is slow because it flushes the stream. There was some discussion years ago about deprecating it because it's not clear about that from the name, but I think the conclusion was that nobody gives a rip about the performance of streams anyway.
Timer class should be simplified so that you use std::chrono::high_resolution_timer::time_point and std::chrono::high_resolution_timer::duration types instead of typing out the base types.
You cannot put the chrono object into the standart stream, you need to convert it to a float/double/int as Cherno does a couple of seconds later.. if you wanted to print out the 'duration' variable, you'd need to print duration.count()
set the font in window properties to the lowest possible, got 15ms lol also i didnt put just to see how low can i get and i also didnt set the compiler to prioritize speed
the difference in runtime for me was negligable / all over the place so I increased the for loop to 1000 and tried a few times and interestingly, in 64bit release mode I get around 720ms for the std::endl solution and 420ms for the solution. Intel i7 7700K btw.
hey, Thanks for this insight. I enjoyed it. I was wondering if "time" could be slowed down or speed up. as example, day and night rhythm. but i want to slow time down from real time and speed it up to 200x real time. I want to incorporate this into a project.
the timing libraries will only tell you about real life timing (how many seconds, miliseconds, etc). What you are describing has to do with how you implement your program loop.
Suggestion: When you display names across the bottom of your screen in white, if you outline them in black it will keep them from disappearing across a light background. Then you would see the outline instead of the words blending in across something else white. Simple design trick. I really appreciate the videos. Thank you.
Don't convert durations yourself using .count(), that's not recommended. Instead, use duration_cast, much better and type safe, plus comes with no overhead (everything done at compile time).
hi ! i get "error: no match for ‘operator=’ (operand types are ‘std::chrono::time_point’ and ‘std::chrono::_V2::system_clock::time_point’ {aka ‘std::chrono::time_point’}) 16 | start = std::chrono::high_resolution_clock::now();" error std:chrono::time_point Changing this part to std::chrono::system_clock::time_point solved the problem. I don't understand Please. could you explain it?
im not too interested in performance really but rather i just want to tinker around with the code , however performance is a nice side benefit i guess :) you'd never find me writing code for python or any of the other index block based programming languages. i might consider java some day but for now i would like to learn c++. maybe i'll try to create my muilti-tool i once had in batch script inside of c++ but then i could add so much more functionality
Excellent video! Up until now, I thought you could only use std::this_thread::sleep_for once you were on a separate thread. I guess I never thought about how the main thread is a thread too.... :)
Call me crazy but; removing endl is useless if you want speed... Why not use printf(); ? Looks like C++ folks always forget C exists and their headers are there. #include not #include
will the compiler do such optimization that call an object`s deconstruct function immediatly when the object do not be used in the rest of its enclosed function,for example,the timer variable
No, that will never happen. That's not an optimization, that would be changing the order of code execution, which of course is illegal for a compiler to do.
@TheChernoProject Just curious how well informed you are with other languages? Obviously the way you think about programming allows you to pick up other ones really quickly but how proficient are you say with Python? Or Javascript? What other things have you learnt while being at EA not specifically related to c++?
Hi. I have a timer for a speed calculation. I have the timing in seconds that I then convert to a double . I would like a milliseconds result. I feel just do *1000 is a bit sloppy. Any advice? Thanks.
When you started this series, I thought I had a decent enough understanding of C++ and didn't need to watch it. I've watched episodes anyway because I enjoy your video style. I've learned so much though. For example, I knew about std::chrono and some profiling methods before watching this, but I've never seen anyone wrap it so nicely in an object and use scope lifetime to their advantage so well. I'll make use of this from now on. So many great tricks to pick up from watching this series! Thanks as always Cherno! :)
yes
same
Wow, You just sounded arrogant, then Cherno Kicked you into Humbleness.
@@ataladin87 no they didn't? they just thought they had a good understanding of c++
This series is so fucking good, keep it up
#include
#include
que es eso
@@danielesquivel3155 chrono trigger es un juego
Nice
In cygwin I had to use
_std::chrono::high_resolution_clock::time_point_
instead of
_std::chrono::time_point_
Just an FYI for anyone getting the error that there is no _'operator='_ on std::chorno::time_point you may want to try the high resolution one.
I had same error in qmake. Thanks!
Justin Chrysler Thanks.
Justin Chrysler I want to know the reason if you know please let me know.
I would assume it has something to do with the way the chrono library is built for each compiler. Each compiler implements the standards differently.
It's the same on the gcc compilers.
Another great video, love that you're using RAII, it's really the best c++ feature.
btw you could have used "std::chrono::duration_cast" for your ms conversion ;)
std::endl is slow beacuse for each line it must flush buffer
On my pc, removing endl and adding
actually made it slower... good 50% slower. weird
@Peterolen It would be important if you are copying large data files or save files or outputting some kind of long report to be read later.
@@them4309 Would have to be a pretty long report to be fair. I would imagine the report would be written to file though as logging it is probably super important.
What does flushing the buffer means?
@@anthonysteinerv He's from New Zealand... they call the toilet the buffer. 👍
Cherno: You are using c++ because you obviously care about performance
ME: Nah , i just want my code to run !!!
xDdDDDD
i felt so smart when i thought of that neat little trick with the timer class before you explained it
i'd like to hear you talk about callbacks in programming/c++. great videos
Very interested to see your upcoming game engine series.
those who are facing issue with chrono::time_point should use chrono::time_point....I think this issue is due to difference in OS( I have linux mint,cherno is using windows)..
This solved it for me. But I was using Windows as well. I think it may be a different VC++ compiler than what Cherno was using.
Or you can just change to use the high_resolution_clock as the templated type given to the time_point constructor. Then the now() methods are returning the same type as the time_point objects (start, end) are expecting. For added fun, I suppose you could also try to cast the steady_clock object to a high_resolution_clock object, and see if that works...lol. Talk about ugly syntax!
The best c++ chanel good job
me: *seeing a C++ tutorial*
me: *opening this tutorial*
cherno's video: *appears*
me: *without watching to the end instantly clicking on cherno's video*
This series is really helpful and I'm looking forward to the game engine series.
Love your videos man.
Great Video Bro 👍👍
excellent as always..hope u do more of these more often.
3:23 literally, it is enlightening moment!
😳 what just happened there?
how 1s is a valid value?
You are so detailed in short videos
Please make one playlist on python also
Good to see you back, Master!
Beautiful presentation. Thank you!
I really liked this video .. like I pressed the Like button with full of thankfulness ... thank you so much for this explanation ❤❤
If you have the type error during struct, change std::chrono::time_point start, end; to std::chrono::time_point start, end;
THANK YOU
hey, im a beginner to c++ and when I try to use the chrono, i keep getting an error that it cant be resolved. I check my version of gcc and its up to date so I have no idea what the issue it. Does anyone know what I could do here?
The Timer structure is a brilliant idea. Thanks!
Awesome video! Never knew about this chrone library. Super handy! :)
#include
will do everything for you
funny side note: I did two functions one with printf and one with cout and the old school c printf was a third of the time
Can u make a video about the "constexpr" stuff?I can't understand how it actualy works .Ty
This helped me a lot, thanks!
The endl keyword is Slow Because Is Flushes all The Output Buffer And Then Put Newline
So great tutorial... Good luck on your way!! Thank you.
Hi Cherno ... I have idea, right click name project and click Properties -> Linker -> System -> SubSystem ... choose Console and OK then your console will stop without infinite loop, etc ...
Thank you, this was a big help
Yan Chernikov ! My C++ Mentor !!
I Learned And Mastered Pointers (* = raw) with your help because these stars thing are too annoying.
Love From Pakistan
std::endl is slow because it flushes the output buffer
For Timer struct fail to compile:
I changed 7th line, and it worked.
std::chrono::time_point start, end;
Hey! Can you do an operator overloading video
a print hello function already 70ms? wondering how then the figh freq trading firm make money? they algo runs at sub mili second.
Awesome video
Why isnt end being initialised in the constructor but instead in the destructor?
You could also manually time functions in your code to see how quick they perform by passing a function pointer to the function that will time it.
Example:
void time_this() {
for(int i = 0; i < 10000; i++) {
std::cout
TheChronoProject
=)
Klaus Uhr Scherzkeks
xDdDDDD
This is genius.
Thanks for this video
How was GDC? anything interesting to share with us?
Woah! Wish I was there -- procedural generation is, one of my favorite topics / things to experiment with.
Isn't it better to use std::chrono::high_resolution_clock::time_point as type of start (6.33)?
Thank you that quickly fixed an issue I had
Why my Timer constructor is shown to be +1 overloaded in visual studio with green squiggles?
Why he said he can't use the auto keyword in the Timer struct constructor
This lessons are great thank you, when is the Game Engine series starting? cheers!!
Muito obrigado!
This video is right on time
As always awesome video, love em all ! I know its some deep stuff but do you have any plans to cover the SIMD (single instruction multiple data ) instruction set ?
Keep up the good work !
Thank you !
Great video but can you tell me what value does now() return
Why is it taking 77 ms? In my system it completes in 0.8 to 1 ms.
std::endl is slow because it flushes the stream. There was some discussion years ago about deprecating it because it's not clear about that from the name, but I think the conclusion was that nobody gives a rip about the performance of streams anyway.
Timer class should be simplified so that you use std::chrono::high_resolution_timer::time_point and std::chrono::high_resolution_timer::duration types instead of typing out the base types.
This could be so useful to me, there are some functions I've been working on that really need profiling.
Hi love your videos. Please make video on different callback methods in c++
How about a video on working with dates and time?
I would like my while loop to cout one line every second, and not all at once
Then you create the struct inside the loop at the beginning an it will destroy itself an make a new one every loop, printing the result
Hey guys! I'm kinda new to c++, so... 8:00 what does duration.count() do?
@Ludvig Sandberg that's not right. Seconds * 1000 is what gives you ms
7:50 line 21 why
using duration.count() works
You cannot put the chrono object into the standart stream, you need to convert it to a float/double/int as Cherno does a couple of seconds later.. if you wanted to print out the 'duration' variable, you'd need to print duration.count()
if you wanted to print just 'duration' you'd need to overload the ostream operator for it to handle it
What is that faking tomato in auto complete?
Hey, what happened about the another thread video !!
set the font in window properties to the lowest possible,
got 15ms lol
also i didnt put
just to see how low can i get and i also didnt set the compiler to prioritize speed
According to this chrono thing, getting the 49th element of recursive Fibonacci sequence takes 149.673 seconds. That's pretty long.
the difference in runtime for me was negligable / all over the place so I increased the for loop to 1000 and tried a few times and interestingly, in 64bit release mode I get around 720ms for the std::endl solution and 420ms for the
solution. Intel i7 7700K btw.
Xcode does provide a profilers but they are not very usable or I'm probably to stupid to use them.
hey,
Thanks for this insight. I enjoyed it.
I was wondering if "time" could be slowed down or speed up.
as example, day and night rhythm.
but i want to slow time down from real time and speed it up to 200x real time.
I want to incorporate this into a project.
the timing libraries will only tell you about real life timing (how many seconds, miliseconds, etc). What you are describing has to do with how you implement your program loop.
interesting. have they changed std::endl?
Timer took 23.6653ms with std::endl;
Timer took 27.7078ms with
Interesting... Can i look ur code?
Suggestion: When you display names across the bottom of your screen in white, if you outline them in black it will keep them from disappearing across a light background. Then you would see the outline instead of the words blending in across something else white. Simple design trick. I really appreciate the videos. Thank you.
Gold here!
Great series! Consice with still being in-depth, plus functional examples.
I had to use decltype(std::chrono::high_resolution_clock::now()) start,end;
Don't convert durations yourself using .count(), that's not recommended. Instead, use duration_cast, much better and type safe, plus comes with no overhead (everything done at compile time).
hi ! i get "error: no match for ‘operator=’ (operand types are ‘std::chrono::time_point’ and ‘std::chrono::_V2::system_clock::time_point’ {aka ‘std::chrono::time_point’})
16 | start = std::chrono::high_resolution_clock::now();" error
std:chrono::time_point Changing this part to std::chrono::system_clock::time_point solved the problem. I don't understand
Please. could you explain it?
im not too interested in performance really but rather i just want to tinker around with the code , however performance is a nice side benefit i guess :)
you'd never find me writing code for python or any of the other index block based programming languages.
i might consider java some day but for now i would like to learn c++.
maybe i'll try to create my muilti-tool i once had in batch script inside of c++ but then i could add so much more functionality
Whats wrong with clock_t time = clock(); ?
Excellent video! Up until now, I thought you could only use std::this_thread::sleep_for once you were on a separate thread. I guess I never thought about how the main thread is a thread too.... :)
Call me crazy but; removing endl is useless if you want speed... Why not use printf(); ? Looks like C++ folks always forget C exists and their headers are there. #include not #include
What's overhead? Thank you for this series btw
What is the advantage of using chrono over ctime?
will the compiler do such optimization that call an object`s deconstruct function immediatly when the object do not be used in the rest of its enclosed function,for example,the timer variable
No, that will never happen. That's not an optimization, that would be changing the order of code execution, which of course is illegal for a compiler to do.
@@TheCherno so there`s no reorder in c++?
please do a video in how to get time
Hey! how about chrono based game loop mean (fps, time and delta time) delays idles etc.
std::endl was actually faster than the escape newline
for me.
Damn the voice echo was really loud back then
Hey Cherno did you talked before about how to handle exceptions??
@TheChernoProject Just curious how well informed you are with other languages? Obviously the way you think about programming allows you to pick up other ones really quickly but how proficient are you say with Python? Or Javascript? What other things have you learnt while being at EA not specifically related to c++?
Can you make a video about move semantics please? :)
What are the main difference between C++ and Java?
Which compiler are u using? and which C++ version
Hi. I have a timer for a speed calculation. I have the timing in seconds that I then convert to a double . I would like a milliseconds result. I feel just do *1000 is a bit sloppy. Any advice? Thanks.
Unless there is a specific millisecond function, then that is the way to do it.
This is does not seem to be working on linux, getting tons of errors of missing operator overloads and so on, using gcc.
Is your target C++ standard correct?
If not then you should pass -std=c++11 (or higher) to the compiler
@@groberti He should pass -std=c++2a
what a cool ass guy
I know it sounds dumb... but I've always done clock() / CLOCKS_PER_SEC :D
Bravissimo
Why does he write "std::" in every statement instead of putting "using namespace std" at the top?
Very useful video btw
There's a whole video about that.