Skip to content

Instantly share code, notes, and snippets.

01:20 denplusplus@denplusplus-desktop:~/Temp/benchmark/nbody$ /usr/bin/g++ -march=native -c -pipe -O3 -fomit-frame-pointer -mfpmath=sse -msse3 nbody.gpp-9.cpp -o nbody.gpp-9.c++.o && /usr/bin/g++ nbody.gpp-9.c++.o -o nbody.gpp-9.gpp_run && rm nbody.gpp-9.c++.o01:20 denplusplus@denplusplus-desktop:~/Temp/benchmark/nbody$ time ./nbody.gpp-9.gpp_run 50000000
-0.169075164
-0.169059907
real 0m5.807s
user 0m5.805s
sys 0m0.000s
01:20 denplusplus@denplusplus-desktop:~/Temp/benchmark/nbody$ rustc -C opt-level=3 -C target-cpu=core2 -C lto -C codegen-units=1 -C target-feature=+sse2 nbody.rs -o nbody.rust-7.rust_run
01:20 denplusplus@denplusplus-desktop:~/Temp/benchmark/nbody$ time ./nbody.rust-7.rust_run 50000000
-0.169075164
// mcs -unsafe -debug- Spaces.cs; time mono -O=all ./Spaces.exe
using System;
using System.Threading.Tasks;
public class Spaces {
static unsafe string GetTest(int len) {
var s = new string(' ', len);
fixed (char* pS = s) {
for (int i = 0; i < len; ++i) {
10:10 denplusplus@denplusplus-mbp:~/Temp/CSharp$ mcs -unsafe -debug- Spaces.cs; time mono -O=all ./Spaces.exe
Total length: 19999990
real 0m0.064s
user 0m0.038s
sys 0m0.023s
10:10 denplusplus@denplusplus-mbp:~/Temp/CSharp$ g++ -O3 Spaces.cpp -o Spaces --std=c++14 -march=native -g -DNDEBUG; time ./Spaces
19999990
real 0m0.012s
03:55 denplusplus@denplusplus-mbp:~/Temp/CSharp$ mcs -unsafe -debug- Spaces.cs; time mono -O=all ./Spaces.exe
'1234567890' -> '1 2 3 4 5 6 7 8 9 0'
real 0m12.823s
user 0m12.609s
sys 0m0.090s
03:55 denplusplus@denplusplus-mbp:~/Temp/CSharp$ g++ -O3 Spaces.cpp -o Spaces --std=c++14 -march=native -g -DNDEBUG; time ./Spaces
1 2 3 4 5 6 7 8 9 0
real 0m4.582s
#include <iostream>
#include <string>
using namespace std;
static string InjectSpaces(const string& s) {
string result(2*s.length() - 1, ' ');
char* pResult = (char*)result.data();
const char* pS = s.data();
const auto length = s.length();
// g++ -O3 Spaces.cpp -o Spaces --std=c++14 -march=native -g; time ./Spaces
#include <iostream>
#include <string>
using namespace std;
static string InjectSpaces(const string& s) {
string result(2*s.length() - 1, ' ');
const auto length = s.length();
using System;
public class Spaces {
public static void Main(string[] args) {
var s = "12345678";
var r = InjectSpaces(s); // r == "1 2 3 4"
for (int i = 0; i < 200000000; ++i) {
r = InjectSpaces(s);
}
Console.WriteLine("'{0}' -> '{1}'", s, r);