#How can I optimise this simple short script?

9 messages · Page 1 of 1 (latest)

white obsidian
#

Hi, I am learning C++ and recently created this script and would like to know ways I could optimise my scripts early on. (other than the sorting method- bubble sort as I already know that this isn't efficient and I know other types of sorting methods I could use instead).

raw plumeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

wild flume
#

I'd recommend not passing and returning std::vectors by value, this necessitates copying the entire vector

#

Instead of std::vector<short> sortArray(std::vector<short> array), do void sortArray(std::vector<short>& array)

#

For optimization it's all about knowing where to optimize. Focus on the "hot" "inner loops" of your program, that's where 90% of execution time will be spent. As a programmer don't worry about micro optimizations, your job is algorithmic optimization. You can eliminate inefficiency with copying arrays around here but really the only other place I'd say is worth optimizing is the algorithm being used for sorting.

white obsidian
#

alright thanks

#

!solved

raw plumeBOT
#

[SOLVED] How can I optimise this simple short script?

raw plumeBOT
#

How can I optimise this simple short script?