All Projects → facontidavide → Cpp_optimizations_diary

facontidavide / Cpp_optimizations_diary

Licence: mit
Tips and tricks to optimize your C++ code

Programming Languages

cpp
1120 projects

Projects that are alternatives of or similar to Cpp optimizations diary

Bitnami Docker Wordpress
Bitnami Docker Image for WordPress
Stars: ✭ 476 (-7.93%)
Mutual labels:  blog
Blogchat
Chat room source code for Barret Lee's Personal Blog.
Stars: ✭ 493 (-4.64%)
Mutual labels:  blog
Jekflix Template
A Jekyll theme inspired by Netflix. 🎬
Stars: ✭ 504 (-2.51%)
Mutual labels:  blog
Awesome Robotics
A curated list of awesome links and software libraries that are useful for robots.
Stars: ✭ 478 (-7.54%)
Mutual labels:  optimization
Autokernel
AutoKernel 是一个简单易用,低门槛的自动算子优化工具,提高深度学习算法部署效率。
Stars: ✭ 485 (-6.19%)
Mutual labels:  optimization
Cms
Decoupled CMS for any Laravel app, gain control of: pages, blogs, galleries, events, images, custom modules and more.
Stars: ✭ 498 (-3.68%)
Mutual labels:  blog
Llvm
Project moved to: https://github.com/llvm/llvm-project
Stars: ✭ 4,461 (+762.86%)
Mutual labels:  optimization
Notcpucores
Work, Play, Stream - Without the Stutter. Download using Releases button below
Stars: ✭ 514 (-0.58%)
Mutual labels:  optimization
Lepto
Automated image Editing, Optimization and Analysis via CLI and a web interface. You give to lepto your input and output directories, the plugins you want to use and their options. Then lepto does his job, you keep your original files and the structure of the input directory. Some plugins can even collect data (like primary colors) from your images and save them in a JSON file.
Stars: ✭ 490 (-5.22%)
Mutual labels:  optimization
Imagemin
[Unmaintained] Minify images seamlessly
Stars: ✭ 4,948 (+857.06%)
Mutual labels:  optimization
Hexo Theme Inside
🌈 SPA, Flat and clean theme for Hexo.
Stars: ✭ 480 (-7.16%)
Mutual labels:  blog
Monologue
Monologue is a basic blogging engine. It is a Rails mountable engine you can mount in your already existing Rails app, or a in a new one! Enjoy.
Stars: ✭ 485 (-6.19%)
Mutual labels:  blog
Bleak
Ghost Theme
Stars: ✭ 497 (-3.87%)
Mutual labels:  blog
Mapache
You can use the theme Mapache for ghost in: Blog - Magazine - Landing page - Personal page - Photographers. and in many other things
Stars: ✭ 477 (-7.74%)
Mutual labels:  blog
Faceswap
3D face swapping implemented in Python
Stars: ✭ 508 (-1.74%)
Mutual labels:  optimization
Blog
CSS大草原(一丝的博客)
Stars: ✭ 476 (-7.93%)
Mutual labels:  blog
Blog
梁少峰的个人博客
Stars: ✭ 4,602 (+790.14%)
Mutual labels:  blog
Hyperparameter Optimization Of Machine Learning Algorithms
Implementation of hyperparameter optimization/tuning methods for machine learning & deep learning models (easy&clear)
Stars: ✭ 516 (-0.19%)
Mutual labels:  optimization
Kails
A Web App like Ruby on Rails with Koa2, Webpack and Postgres
Stars: ✭ 512 (-0.97%)
Mutual labels:  blog
Fullstack React
A simple, full-stack JavaScript single page app featuring React, Webpack, and Falcor
Stars: ✭ 503 (-2.71%)
Mutual labels:  blog

Preface: about me

My name is Davide Faconti and my job is one of the best in the world: I work in robotics.

This blog/repository is maintained in my spare time and it is not related to my work there. Therefore opinions (and memes) are all mine and don't represent my employer in any way.

I love C++ programming and Open Source and this "diary" is my small contribution to the OSS community.

CPP Optimizations Diary

Optimizing code in C++ is something that no one can resist. You can have fun and pretend that you are doing something useful for your organization at the same time!

In this repository, I will record some simple design patterns to improve your code and remove unnecessary overhead in C++.

If you are a seasoned C++ expert, you probably have your own set of rules already.

These rules help you look like a bad-ass/rockstar/10X engineer to your colleagues.

You are the kind of person that casually drops a std::vector<>::reserve before a loop and nods, smiling, looking at the performance improvement and the astonishment of your team member.

Hopefully, the examples in this repository will help you achieve this status of guru and, as a side effect, save the planet from global warming, sparing useless CPU cycles from being wasted.

Then, unfortunately, someone on the other side of the planet will start mining Bitcoins or write her/his application in Python and all your effort to save electricity was for nothing.

I am kidding, Python developers, we love you!

Narrator: "he was not kidding..."

Rule 1: measure first (using good tools)

The very first thing any person concerned about performance should do is:

  • Measure first and make hypothesis later.

Me and my colleagues are almost always wrong about the reasons a piece of code is slow.

Sometimes we are right, but it is really hard to know in advance how refactoring will improve performance. Good profiling tools show in minutes the "low hanging fruits": minimum work, maximum benefit!

Summarizing: 10 minutes profiling can save you hours of guessing and refactoring.

My "goto" tools in Linux are Hotspot and Heaptrack. I understand Windows has similar tools too.

In the benchmark war, if you are the soldier, these are your rifle and hand grenades.

Once you know which part of the code deserves to be optimized, you might want to use Google Benchmark to measure the time spent in a very specific class or function.

You can even run it Google Benchmark online here: quick-bench.com.

quick-bench

Rule 2: learn good design patterns, use them by default

Writing good code is like brushing your teeth: you should do it without thinking too much about it.

It is a muscle that you need to train, that will become stronger over time. But don't worry: once you start, you will start seeing recurring patterns that are surprisingly simple and works in many different use cases.

Spoiler alert: one of my most beloved tricks is to minimize the number of heap allocations. You have no idea how much that helps.

But let's make something absolutely clear:

  • Your first goal as a developer (software engineer?) is to create code that is correct and fulfil the requirements.
  • The second most important thing is to make your code maintainable and readable for other people.
  • In many cases, you also want to make code faster, because faster code is better code.

In other words, think twice before doing any change in your code that makes it less readable or harder to debug, just because you believe it may run 2.5% faster.

Get started

For a more comfortable reading experience, visit: https://cpp-optimizations.netlify.app

Optimization examples

"If you pass that by value one more time..."

std::vector<> is your best friend

"It is just a string, how bad could that be?"

Don't compute things twice.

Fantastic data structures and where to find them.

Case studies

License

This work is licensed under CC BY-SA 4.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].