C++ performance vs. Java/C#

JIT vs. Static Compiler As already said in the previous posts, JIT can compile IL/bytecode into native code at runtime. The cost of that was mentionned, but not to its conclusion: JIT has one massive problem is that it can’t compile everything: JIT compiling takes time, so the JIT will compile only some parts of … Read more

Does the order of LINQ functions matter?

It will depend on the LINQ provider in use. For LINQ to Objects, that could certainly make a huge difference. Assume we’ve actually got: var query = myCollection.OrderBy(item => item.CreatedDate) .Where(item => item.Code > 3); var result = query.Last(); That requires the whole collection to be sorted and then filtered. If we had a million … Read more

Most efficient way to make the first character of a String lower case?

I tested the promising approaches using JMH. Full benchmark code. Assumption during the tests (to avoid checking the corner cases every time): the input String length is always greater than 1. Results Benchmark Mode Cnt Score Error Units MyBenchmark.test1 thrpt 20 10463220.493 ± 288805.068 ops/s MyBenchmark.test2 thrpt 20 14730158.709 ± 530444.444 ops/s MyBenchmark.test3 thrpt 20 … Read more

Coding Practices which enable the compiler/optimizer to make a faster program

Here’s a coding practice to help the compiler create fast code—any language, any platform, any compiler, any problem: Do not use any clever tricks which force, or even encourage, the compiler to lay variables out in memory (including cache and registers) as you think best. First write a program which is correct and maintainable. Next, … Read more

Python vs Bash – In which kind of tasks each one outruns the other performance-wise? [closed]

Typical mainframe flow… Input Disk/Tape/User (runtime) –> Job Control Language (JCL) –> Output Disk/Tape/Screen/Printer | ^ v | `–> COBOL Program ——–‘ Typical Linux flow… Input Disk/SSD/User (runtime) –> sh/bash/ksh/zsh/… ———-> Output Disk/SSD/Screen/Printer | ^ v | `–> Python script ——–‘ | ^ v | `–> awk script ———–‘ | ^ v | `–> sed … Read more

Most efficient way of making an if-elif-elif-else statement when the else is done the most?

The code… options.get(something, doThisMostOfTheTime)() …looks like it ought to be faster, but it’s actually slower than the if … elif … else construct, because it has to call a function, which can be a significant performance overhead in a tight loop. Consider these examples… 1.py something = ‘something’ for i in xrange(1000000): if something == … Read more

Is String.Contains() faster than String.IndexOf()?

Contains calls IndexOf: public bool Contains(string value) { return (this.IndexOf(value, StringComparison.Ordinal) >= 0); } Which calls CompareInfo.IndexOf, which ultimately uses a CLR implementation. If you want to see how strings are compared in the CLR this will show you (look for CaseInsensitiveCompHelper). IndexOf(string) has no options and Contains()uses an Ordinal compare (a byte-by-byte comparison rather … Read more