13

EDIT: Thanks to @benrg pointing out a bug of the previous algorithm. I have revised the algorithm and moved it to the second part since the explanation is long. While the other answer focuses more on coding style, this answer will focus more on performance. Implementation Improvements I will show some ways to improve the performance of the code in the ...


11

You are inconsistent with your use of the this. 'suffix'. Nobody can agree on this, but you should try to be consistent without projects. I would remove the return values from every method which modifies Vector3: you have 2 copies of Min, and one is very confusing. All of the methods which happen to produce a vector (e.g. Abs, Min, Max) happen to ...


10

On the logic, you should notice that the next state of the i'th house becomes state[i - 1] ^ state[i + 1] (some care at the boundaries to be exercised). Upon the closer inspection you may also notice that if you represent the state of the entire block as an integer composed of bits from each house, then state = (state << 1) ^ (state >> 1) is ...


8

You seem to be jumping through some unnecessary hoops. Just format a string directly: from timeit import timeit def _channel_to_hex(color_val: int) -> str: raw: str = hex(color_val)[2:] return raw.zfill(2) def rgb_to_hex(red: int, green: int, blue: int) -> str: return "#" + _channel_to_hex(red) + _channel_to_hex(green) + _channel_to_hex(...


5

Documentation The amount of documentation you've written is ambitious, but its arrangement is slightly unhelpful for a few reasons. When documenting the "parameters to a class", you're really documenting the parameters to __init__. As such, this block: """ Parameters ---------- shapefile : str It is a string pointing to a ...


5

Hash code collisions There's a problem with Commit: matching hash codes do not mean that two objects are equal ('pigeonhole principle'). For example, both [1, 0] and [0, 31] have hash code 31. You can only be sure that objects are not equal when their hash codes don't match - the inverse is not true. Also, are you sure that reusing arrays is worth the ...


5

Enumerate Instead of writing range(len()), consider using enumerate. It provides the index and the value associated with that index. It's useful in your case because, instead of having to write in_states[i], you can write value instead. This will save you from having to index the list again with in_states[i]. Docstrings You should provide a docstring at ...


5

A significant performance drain is bit-by-bit computation loops such as TypeBase<Size> &operator+=(const TypeBase<Size> &other) { bool carry = false; for (size_t ix = 0; ix < Size; ++ix) { data_[ix] = add_(data_[ix], other.data_[ix], carry); } return *this; } Unfortunately, at this time such constructs are ...


4

Adding to the other reviews, here are a few more points. Outside-class Functions vs. Methods Here is a long discussion about function and methods. In general, if a function operates only on instances of a class (including its subclasses), it should be a method of that class. In your program, most of the functionality of the three functions decToBase, ...


4

Hello and Welcome to Code Review. The runtime complexity in terms of reading characters (n files * m characters) for substitution cannot be improved, you can use the String replace(char oldChar, char newChar) method: String childName = file.getName(); String childNameNew = ""; for (int i = 0; i < childName.length(); i++) { if (childName.charAt(i) == '...


4

Code style Try to use an IDE which integrates with linters (Pycodestyle, Pylama, Mypy,...). This alone found some 97 warning, ranging from no whitespaces after a comma, trailing whitespace, redundant backslashes, closing brackets not matching the indentation,... All of these are no big issues, but they make the code look messy, and are easy to fix. I use a ...


3

Another approach to generate the hex string is to directly reuse methods of format strings rather than writing your own function. rgb_to_hex = "#{:02x}{:02x}{:02x}".format # rgb_to_hex(r, g, b) expands to "...".format(r, g, b) rgb_tup_to_hex = "#%02x%02x%02x".__mod__ # rgb_tup_to_hex((r, g, b)) expands to "..." % (r, g, b) These are faster (...


3

It might be boring to hear it again, but I have to ask :) Why do you think your application need performance optimisations? Is your bottle neck in these parts of code which you provided? Maybe problem is with database/external service/network? Have you measured processing and communication time? Stopwatch Do you have some kind of monitoring of application, ...


3

COUNTIF() is slow. A few COUNTIF() statements in a worksheet can be okay, but thousands of them will result in a glacial spreadsheet. Here is a way to replace your COUNTIF() statements: Sort Column A. In Column B, have each cell check if the corresponding cell in column A is equal to the cell above it in column A. If no, put 1 in column B's cell. If yes,...


3

For continuous monitoring I agree with Zer0 to look at the % time spent in GC performance counters. However for a session based analysis a more informative approach would be to collect the ETW traces from .NET. You can see here for the different GC related events, GCStart and GCEnd would most likely be relevant for you. view the .NET documentation for ...


3

def decToBase(n: int, b: int) -> list: def baseToDec(n: list, b: int) -> int: These names reflect a common misconception. int is not inherently decimal. If any named base were appropriate, it would be bin for binary. But it's far more sensible to think of int as being int: either call them int to base and base to int or, IMO better, base compose and ...


2

As dariosicily said, the complexity can not be improved but there are some really dirty tricks you can do to improve performance by minimizing the number of objects being created... Keep in mind that this optimization is a bit useless if you only have a few thousand files with short names or if the number of files needing renaming is large compared to the ...


2

if (Hashes.TryGetValue(tempHash, out List<int> key)) { Commits.Add(commitNumber, Commits[key[0]]); Hashes[tempHash].Add(commitNumber); Be consistent: you've already got an alias for Hashes[tempHash], so use it. Also, on the subject of names, why tempHash instead of just hash? And key for the value of a KeyValuePair is a ...


2

bind_front can (and should) be made constexpr. The callable object and the bound arguments need to be decayed per the standard. You can store all arguments in a tuple instead of generating nested wrappers: template <class FD, class... Args> class bind_obj { // ... FD func; std::tuple<Args...> args; }; and then call std::apply(...


2

Numpy is your best friend. Given your comment: The tuples are produced by "color scheme" functions. The functions take the (real, imaginary) coordinates of the pixel and how many iterations it took that pixel to fail, and return a three-tuple. They could return anything to indicate the color (that code is completely in my control), I just thought a three-...


2

memoization The _channel_to_hex is called 3 times per pixel. It only takes 256 different inputs, so a logical first step would be to memoize the results. This can be done with either functools.lru_cache from functools import lru_cache @lru_cache(None) def _channel_to_hex(color_val: int) -> str: raw: str = hex(color_val)[2:] return raw.zfill(2) ...


1

Performance The recursive function is as fast as I can think of. The iterative function should enqueue root.left and root.right instead of root and root to gain a cycle (micro-optimisation). Review I find it weird that the null node is considered symmetric IsSymmetric(null). I would throw an error for invalid input. Both algorithms are not able to deal ...


1

Some quick remarks: GetBuilds does multiple things, so split that up into smaller methods that each do a specific job. And then check which of those methods causes the issues. Use Dapper instead of ADO.NET. (Why are you even mixing ADO.NET and Entity Framework?) Are the DB properties you do INNER JOINs on properly indexed? Don't add "Class" to the name of ...


1

Are there some cases in std::bind_front that I missed? There are several significant differences between std::bind_front's behavior and your implementations. First, your implementation unconditionally returns a value. But what if the callable in question returned a reference? The behavior is just incorrect. Second, std::bind_front is SFINAE-friendly but ...


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