Skip to content

Instantly share code, notes, and snippets.

@nlguillemot
nlguillemot / MillionItemList.cpp
Created June 25, 2012 00:57
Comparison of performance of adding elements to preallocated containers in c++11
#include <vector>
#include <list>
#include <iostream>
#include <ctime>
// FIXME: v(1000000) creates a vector of 1000000 elements. At the end of the function there are 2000000 elements. Instead, it should be constructed empty and then v.reserve(1000000) should be called just after.
void createPreallocatedMillionVector()
{
std::vector<int> v(1000000);
@nlguillemot
nlguillemot / output with g -stdc0x -O2
Created July 1, 2012 04:06
Comparison of performance of adding elements to containers in C++
Vector took 0.18 seconds.
Preallocated Vector took 0.1 seconds.
Back pushed List took 1.38 seconds.
Front pushed List took 1 seconds.
Front pushed Pool allocated list took 0.67 seconds.
In other words,
Preallocating a vector makes it ~200% faster than not preallocating
Pushing to the front makes it ~150% faster than pushing to the back
Pushing to the front and using a pool allocator makes it ~200% faster than pushing to the back
@nlguillemot
nlguillemot / HashedString.hpp
Created July 14, 2012 18:50
better HashedString class
#ifndef HASHEDSTRING_HPP_INCLUDED
#define HASHEDSTRING_HPP_INCLUDED
#include <irrlicht/irrTypes.h>
// if HASHEDSTRING_USE_CONSTEXPR is defined, a recursive constexpr hashing algorithm will be used.
// otherwise, an iterative runtime hashing algorithm will be used.
#define HASHEDSTRING_USE_CONSTEXPR
// do not touch this block of preprocessor.
@nlguillemot
nlguillemot / HashedString.cpp
Created July 17, 2012 19:27
Compile-time hashed strings with unit test
#include <cstdint>
// if HASHEDSTRING_USE_CONSTEXPR is defined, a recursive constexpr hashing algorithm will be used.
// otherwise, an iterative runtime hashing algorithm will be used.
#define HASHEDSTRING_USE_CONSTEXPR
// do not touch this block of preprocessor.
#ifdef HASHEDSTRING_USE_CONSTEXPR
#define HASHEDSTRING_CONSTEXPR_IMPL constexpr
#else
@nlguillemot
nlguillemot / hashstr.cpp
Created July 20, 2012 06:55
comparison of constexpr hashed string with assembly
#include <iostream>
constexpr unsigned _hash_string_recursive(unsigned hash, const char* str)
{
return ( !*str ? hash :
_hash_string_recursive(((hash << 5) + hash) + *str, str + 1));
}
constexpr unsigned hash_string(const char* str)
{
@nlguillemot
nlguillemot / hashstr.cpp
Created July 20, 2012 07:22
compile time string hashing and assembly comparison
#include <iostream>
constexpr unsigned _hash_string_recursive(unsigned hash, const char* str)
{
return ( !*str ? hash :
_hash_string_recursive(((hash << 5) + hash) + *str, str + 1));
}
constexpr unsigned hash_string(const char* str)
{
@nlguillemot
nlguillemot / BAD EXAMPLE NUMBER 2 hashstr.cpp
Created July 20, 2012 07:39
constexpr string hashing compiler behaviour
#include <iostream>
constexpr unsigned _hash_string_recursive(unsigned hash, const char* str)
{
return ( !*str ? hash :
_hash_string_recursive(((hash << 5) + hash) + *str, str + 1));
}
constexpr unsigned hash_string(const char* str)
{
@nlguillemot
nlguillemot / practice.md
Created August 7, 2012 06:55
practice test for SENG 271

OO Concepts

Define the following terms in OO context.

  • class
  • object
  • interface
  • abstract
  • concrete
  • inheritence
  • composition
@nlguillemot
nlguillemot / woo
Created November 23, 2012 07:53
banana
# core {{{
[core]
editor = vim
# }}}
# user {{{
[user]
name = Nicolas Guillemot
email = nlguillemot@gmail.com
# }}}
@nlguillemot
nlguillemot / gist:5410561
Created April 18, 2013 06:16
dmd main.d -L-lDerelictGL3
import derelict.opengl3.gl3;
void main(){
DerelictGL3.load();
}
/usr/local/lib/d/libDerelictGL3.a(gl3_8d_649.o):(.data+0x38): undefined reference to `_D8derelict4util6loader15SharedLibLoader7__ClassZ'
/usr/local/lib/d/libDerelictGL3.a(gl3_8d_649.o):(.rodata+0x2508): undefined reference to `_D8derelict4util6loader15SharedLibLoader4loadMFZv'
/usr/local/lib/d/libDerelictGL3.a(gl3_8d_649.o):(.rodata+0x250c): undefined reference to `_D8derelict4util6loader15SharedLibLoader4loadMFAyaZv'
/usr/local/lib/d/libDerelictGL3.a(gl3_8d_649.o):(.rodata+0x2510): undefined reference to `_D8derelict4util6loader15SharedLibLoader4loadMFAAyaZv'