Linked Questions
272
votes
7answers
20k views
What is “cache-friendly” code?
Could someone possibly give an example of "cache unfriendly code" and the "cache friendly" version of that code?
How can I make sure I write cache-efficient code?
2
votes
0answers
64 views
Is it bad to execute if(false) many times?
If I have a piece of code like so...
if(!hasRunMethod) {
runMethod();
hasRunMethod = true;
}
...and that code is being executed in a loop over and over, many times every second, even though ...
0
votes
1answer
30 views
Retrieve key when subkey equals a specifc value in PHP
Is there a simpler than:
foreach ($array as $key => $value) {
if($value['date']->ID == 22) { echo $key; }
}
for searching for ID->22 (each ID is unique) and then if it exists, return ...
4
votes
5answers
197 views
Which real use cases exist for arithmetic right bit shifting?
I stumbled upon a question that asks whether you ever had to use bit shifting in real projects. I have used bit shifts quite extensively in many projects, however, I never had to use arithmetic bit ...
3
votes
1answer
493 views
Double-Compilation of C Code to Decrease Execution Times
According to this article/video:
GCC recognizes several architecture-dependent optimizations for
increasing the speed of C executables. Passing an executable through
GCC a second time can ...
1838
votes
9answers
245k views
28
votes
7answers
2k views
Optimizing very often used anagram function
I have written a function that determines whether two words are anagrams. Word
A is an anagram of word B if you can build word B out of A just by rearranging
the letters, e.g.:
lead is anagram of ...
2
votes
5answers
139 views
Is there an equivalent to the “for … else” Python loop in C++?
Python has an interesting for statement which lets you specify an else suite.
In a construct like this one:
for i in foo:
if bar(i):
break
else:
baz()
the else suite is executed after the ...
-1
votes
1answer
132 views
PowerShell script to export a list of file names only with no file extension then output to a text file separate for each directory
I need a PowerShell script to export a list of file names only with no file extension then output to a text file separate for each sub-folder. I need to specify a parent directory in the script, then ...
5
votes
3answers
91 views
VBA Short-Circuit `And` Alternatives [duplicate]
VBA doesn't short-circuit
VBA does not support short-circuiting - apparently because it only has bitwise And/Or/Not etc operations. From the VBA language specification: "Logical operators are simple ...
0
votes
1answer
21 views
How can I determine the number of arithmetic operations per second of a processor?
What is the best way to determine how many additions, multiplications, exponentiations etc does a processor perform per second according to its specifications (frequency, memory type etc)? E.g. an ...
177
votes
8answers
19k views
Ternary operator is twice as slow as an if-else block?
I read everywhere that ternary operator is supposed to be faster than, or at least the same as, its equivalent if-else block. However, I did the following test and found out it's not the case.
...
449
votes
9answers
42k views
How to disable all caps menu titles in Visual Studio
I assume the title is self explanatory. Just want to change the look of the Visual Studio 2012 not to show menu title in all capital letters.
7
votes
7answers
721 views
check positive or negative without using conditional statements in java
An interview question I was asked last week:
I need a function to print out whether a number is positive or negative without using conditional statements like if else while for switch a? b:c etc. ...
1
vote
2answers
391 views
How to make this python script fast? (benchmarking related to branch prediction from a post from here)
From here - a branching prediction problem, I started to write the Python version of the program to check the runtime of the sorted/unsorted versions in Python.
I tried sorted first.
Here's the ...