Let's talk about the importance of optimizing code structure.

Author: Cousins, Created: 2021-05-22 05:57:14, Updated:

Since it is an open-source program, there are often some minor problems. Today we'll talk about the importance of optimizing code structures.

The most important thing is two things: (1) the utilization of funds; (2) the speed of ordering.

The speed of the order can generally be solved by relying on the nearest server to the exchange, buying a better network, etc. But in fact, for most newcomers, just optimizing the code structure can make the strategy a few tens of milliseconds faster, completely inferior to the effect of changing a better network. However, the cost is much lower.

However, when there is only one transaction pair, the speed of optimization of the code structure is often less than 1 ms, making little difference.

The benefits of optimizing the code structure are obvious. The complexity of multi-trading on the routing is O ((n!), by optimizing it completely can be reduced to O ((n!/(m!)) and even O ((n*m) ((m

I'm going to ask you a question that I often get, for example, that there are two paths A-C and A-B-C, and I'm going to ask you a question about how to do it. The two paths need to be calculated twice, once to calculate the profit path, assuming p1 and p2, once to calculate the path specific to each exchange and its transaction for the specific price and amount to be charged.

One of the most common types of write-through is to write a function that calculates the profit, specifically price and amount. The function is then called in a loop, obtaining the profit of each path, and then choosing the largest profit for the transaction.

Obviously, we only need to calculate the profit when comparing, without having to calculate the price and the amount of the withdrawal from the beginning.

So in optimization, you can split the profit and call function into two functions. First, call the function that calls the profit, get the profit of each path, and then choose the largest to make the transaction. This logically turns the call from each call to only one call. The time complexity changes from O (((2n to O (((n+1), n to the total number of call paths.

Then, if the code is analyzed further, it is found that in most cases, once a path is profitable, it is often profitable at the time, because there are other paths that are profitable.

So we can further optimize the strategy, set up a loop, loop plus if statement, break out if a path is found to have a profit, and then calculate the number of bids and the price of that path.

Then the complexity is further simplified from O ((n+1) to O ((m+1), m

The time complexity can be reduced from O ((2n) to O ((n/2+1)) by analyzing the logical optimization structure using a simple decomposition function.

In fact, there are a lot of scenarios that can be optimized when writing code, and I often find that after writing code, it is possible to optimize the logic of an O ((n!) to O ((n* ((n+1)); sometimes even to optimize a logic that can only be executed for a few hundred milliseconds, to within 1 ms.

As a small amount of time can significantly reduce the strategic query interval, it is recommended that you optimize the code structure.


More

The bone knifeI would like to know how to effectively avoid the situation of one-leggedness in the case of interest rate swaps.

CousinsDelays in the arrival of pending orders

allez-zIs the delay a delay in deep data?

CousinsRecord delays, exceeding a certain value at the time the interest rate is not carried out.