6

Lots of good comments already given. I'll just point out that you should most likely not be writing your own math primitives. It's easy to get wrong, it takes time away from actually creating what you're trying to create, you'll tear your hair out fixing hard to spot bugs and your code (contrary to what most people who write their own math primitives seem ...


5

General - it might be better to create a matrix class and your own vector class in a namespace. Allow The Tools to Help You Improve the Code There are compiler settings that can help you improve your code, these can be specific the the c++ compiler you are using or they can be common. A common c++ compiler switch is -Wall which indicates a errors and ...


4

A few observations: s_t = np.zeros(n) and r_t = np.zeros(n) are more than you need. Since you don't actually use the array values but solely overwrite them, you can use np.empty here. You're doing quite a bit of redundant work in the for loop. When calculating s_t[i], numpy basically has to repeat all the computations it has already done for s_t[i-1]. If ...


3

Without same table and data scripts it is very hard to identify performance issues. However, here are a few observations that might help: Unless I'm reading this wrong, this seems pointless, just adding overhead: ON ((r.ArrivalAirportIATA <> r1.DepartureAirportIATA) OR (r.ArrivalAirportIATA = r1.DepartureAirportIATA)) When using expressions, ...


3

I see some things that I think could help you improve your code. Don't abuse using namespace std Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid. Eliminate global variables where practical Having routines dependent on global variables makes it that much more difficult to understand the logic and ...


3

You tagged laravel, so this answer assumes you are using Laravel. Laravel has two built in helper functions that will help you do this. class_basename() will return the name of the class with the namespace stripped off, and snake_case() will convert a string to snake case. Combine them, and you get: public function getModelName() { return snake_case(...


3

I'm not sure what your optimizations are doing(comments would be nice), but I did notice several inefficiencies: Never include a calculation in the limit test in a for loop. It get's re-calculated on every iteration. In this case set the limit to sqrt(limit). the calculation is kind of expensive but it's done only once. The same goes for the iteration ...


3

Congratulations to you for finding a major bottleneck yourself. There are a few more to get rid of. Generally speaking it's quite a performance killer to convert data between Python and numpy repeatedly. And you do that a lot. You even do it to determine the number of iterations for some loops, e.g. in for j in range(np.array(alphas).shape[1]):. Since ...


2

Well, your regex solution is obviously badly broken - it will fail if the attributes are in a different order, if they are separated by newlines, if they are delimited by single quotes, etc etc. If you try to replace it with a more correct regex (it will never be 100% correct of course) then you are quite likely to lose some of this speed - perhaps ...


2

You can simplify bin(...)[2:].zfill(columns) to f'{...:0>{columns}b}'. This can use f'{int(row[:2], 16):0>{columns}b}'. I'd recommend you convert to a NumPy array out of the function, as it's not really that important to be in there. Your code isn't idiomatic, as Python uses snake_case not camelCase. def from_hex(values, columns): return [ ...


2

General suggestions: black can automatically format your code to be more idiomatic. isort can group and sort your imports automatically. flake8 with a strict complexity limit will give you more hints to write idiomatic Python: [flake8] max-complexity = 4 ignore = W503,E203 That limit is not absolute by any means, but it's worth thinking hard whether you ...


1

That will not speedup your code, but there are some code improvements: follow naming conventions getAttribute -> get_attribute https://visualgit.readthedocs.io/en/latest/pages/naming_convention.html You can create set using set literal my_set = {1, 2, 3} You can compile tableReg = re.compile(r"^.+?(?<=[.])") once


1

Comparison A comparison of performance of 2 classes only makes sense if both adhere to the same specification. Does your class do what a ConcurrentDictionary does? Review Why would you allow access to the underlying dictionary? If you must allow it, return a IReadOnlyDictionary. Checking arguments before taking a lock prevents unnecessary locks on bad ...


1

Don't like this: if(i > preroll) { t += duration_cast<duration<double>>(high_resolution_clock::now()-start).count(); } The call to finish the clock is inside the if statement. Thus you are timing branch failure successes. auto end = high_resolution_clock::now(); if(i > preroll) { t += duration_cast<...


1

Problems There is one correcntness and two performance problems with your approach, both connected with running through the problem from the high numbers and down. For the correctness problem consider the number 91, it has the factorization of 7*13, but your approach would find 7 to be the largest, since 9 < 91**0.5 < 10 < 13, but the correct one ...


1

#define int long long Not only is redefining int a bad idea, but using long long should be reserved for legacy code. Use <cstdint> and (given the ranges used in this code) std::uint_fast32_t. if (limit > 2) cout<<"2 "; if (limit > 3) cout<<"3 "; ... 21 lines ... for(int i=sieve._Find_first();i< ...


1

Here are a few things you could try... Including those mentioned by @tinstaafl I think that you can avoid a lot of the computations. I had a brief look at the Wikipedia page, it seems that you are otherwise properly following the algorithm. #include<bitset> #include<vector> #include<iostream> #include<algorithm> #pragma GCC target (...


1

Subclassing What's the point of this code? Since __CLASS__ always refers to the class in which the code appears, rather than the class of the current object, this method doesn't work with subclassing. That is, with the following code, (new SubModel())->getModelName() would produce base_model, not sub_model: class BaseModel { public function ...


1

Efficiency & Clarity For efficiency the only "flaws" (it's more for "good habit" than noticeable optimization - it doesn't matter for such a small strings) would be the order of functions (regexp is costly so it should be called on string processed as far as possible) and regexp itself which could be optimized for least amount of steps. When it comes ...


Only top voted, non community-wiki answers of a minimum length are eligible