Any good short reads on optimisation of code? (math-specific)

In summary, the author is having a problem with multiple ways of coding, and wants to know if there are any resources to help him speed up the process.
  • #1
mikeph
1,235
18
Hello

I am trying to speed up a code which performs a number of tasks on a set of data. I am wondering if there are any resources on general rules and principles that can be used to speed up calculation times?

I am having a real problem when there appear to be more than one way to code something, I cannot prove to myself why one is faster than the other. I realize this is very non-specific, but I do remember a couple of computer science majors emphasising to me that there are certainly very 'good' and 'bad' ways of coding. If anyone knows any resources applied to maths coding, I would be INCREDIBLY grateful.

Regards,
Mike
 
Physics news on Phys.org
  • #2
The best source I've found (and this is not a quick read) for software construction is Steve McConnell's "Code Complete," published by Microsoft Press. The first edition was published in 1993, but there is a newer edition.

The best book on optimization, IMO, is The Zen of Code Optimization, by Michael Abrash, published by Coriolis Group Books in 1994. This book is all x86 assembly, so if you don't know assembly it won't be much use to you. Inasmuch as this book is 15 years old, much of the optimization that it covers is probably done by compilers. Unless your CS friends are very sharp, it's probable that the tricks they know for optimizing code don't really result in faster-executing code. The compilers that are out there these days are pretty good at optimizing throughput for the multiple pipelines in the Intel architecture chips.
 
  • #3
Making less calls to hard-drive and utilizing the memory can also speed up the things. I am also facing similar problem now where I need to get (historical and real time) data from four sources and perform analysis at every few intervals. I can get historical data during midnight and keep real time data in memory.. but that just one of the ways I have come up with to speed up the things. In my case, analysis is quick but making calls to other programs/data is very expensive.
 

1. What is the purpose of optimizing code?

The purpose of optimizing code is to improve the efficiency and performance of a program or algorithm. This can lead to faster execution times, reduced memory usage, and overall improved user experience.

2. How can I optimize my code for mathematical operations?

One way to optimize code for mathematical operations is to use efficient data structures and algorithms, such as arrays and loops, instead of individual variables and repeated calculations. Additionally, using built-in functions and libraries specifically designed for mathematical operations can also improve code optimization.

3. Are there any shortcuts or tricks for optimizing code?

While there are no universal shortcuts or tricks for optimizing code, there are some general principles that can help improve optimization. These include avoiding unnecessary operations, using efficient data types, and minimizing memory usage.

4. How do I know if my code is optimized?

One way to determine if your code is optimized is to benchmark it against other similar programs or algorithms. You can also use tools such as debuggers and profilers to analyze the execution time and memory usage of your code.

5. Is it worth the time and effort to optimize code?

Optimizing code can have significant benefits, such as improved performance and user experience. However, the time and effort required for optimization should be weighed against the potential gains. In some cases, the benefits may not outweigh the cost, so it is important to consider the specific needs and goals of the project before investing time in optimization.

Similar threads

  • STEM Academic Advising
Replies
11
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Computing and Technology
Replies
3
Views
2K
Replies
15
Views
4K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
24
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
17
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
2
Views
997
Back
Top