Coding Tidbit

Software articles that can be consumed quickly

  • Home
  • About
  • January 16, 2020

    C++17: Benchmark of Singular Min/Max and Iterator Versions

    The benchmark code is hosted at GitHub. In this tip, we’ll benchmark native operator with singular min()/max() and iterator versions like min_element()/max_element(). Lastly, we benchmark the combined operations with minmax_element(). This is the benchmark code. const size_t MAX_LOOP = (argc == 2) ? atoi(argv[1]) : 1000; using int_type = uint64_t; std::vector vec(1000000); std::iota(vec.begin(), vec.end(), 1); […]

  • January 16, 2020

    C#: Never Test For NaN With Equality Test

    Let's write a simple program to test. To get a NaN, we do a 0/0 and store it in num. First of all, the divisor has to be a float-point type because DivideByZeroException shall be thrown for integer or decimal zero divisor. Note: Non-zero number divided by zero (float) gives an infinity number. In our […]

  • January 12, 2020

    Shh…Your interviewer didn’t have the answers to his technical questions!

    Advice for suitable type of technical question to ask in an interview   Write code to sum up from 1 to 100 One has to especially careful when the question is deceptively simple, for instance, sum up all the numbers from 1 to 100. A simple summing loop wouldn’t suffice to satisfy your interviewer. He […]

  • January 9, 2020

    No Code is the Fastest Code

    Optimization of finding a point with shortest distance w.r.t. a point of interest The benchmark source code is hosted at Github. Table of Contents Introduction Shortest Distance Benchmark Results History Introduction When it comes to optimization, majority of developers turn to parallelism but per CPU core isn’t cheap. We could look to eliminate some operations […]

  • January 2, 2020

    C++14/20 Heterogeneous Lookup Benchmark

    Download the benchmark code on GitHub. C++14 introduced ordered transparency lookup which enables const char* and string_view lookup without string instantiation on map/set objects. C++20 introduced unordered transparency lookup that allows to do same thing with unordered_map/unordered_set. We are officially in 2020 but as of writing time, the C++20 Standard is yet to be ratified […]

  • January 1, 2020

    Succinct Guide to Floating-Point Format For C++ and C# Programmers

    Floating-Point Dissector is available for download at GitHub. Table of Contents Introduction Floating-Point Dissector Common Misconceptions Floating-Point Conversion to Integer 32-Bit Floating-Point Format Zero Subnormal (Underflow) Subnormal are much slower on Intel processor Infinity (Overflow) Not a Number Summary Chart Floating-Point Exception Equality Test Other Types References Introduction The IEEE 754 standard for floating-point format […]

  • December 23, 2019

    Lee Algorithm Mazesolver in Direct2D

    Table of Contents Introduction Lee Algorithm for Mazesolving Important Notes Direct2D Code References History Introduction In 1999, my team won Obstacle Avoidance Robot(OAR) first prize in the Singapore Robotics Games(SRG). That was 20 years ago. I do not have a photo of OAR, but it looks very much like micromouse. The micromouse maze is constructed […]

  • December 21, 2019

    C# 7: ref returns and locals

    Table of Contents Introduction ref-return on Value Member Benchmark Conclusion Reference History Introduction C# 7 introduced ref-local and ref-return functionality to allow safe direct-memory access to value variables. Before C# 7, we could do it in an unsafe code but now is available to access in a safe way. This is an example of ref-local […]

  • August 24, 2019

    Bring Your C++ OpenGL Code to the Web

    Table of Contents Introduction Render Function Setting up OpenGL with SDL2 Setting up OpenGL with Emscripten OpenGL Shader Precision Inline your Shader Code Load Asset Introduction Prior to reading this article, that is if you have not setup your Emscripten, you have to read this article: Bring Your C++ Code to the Web. Let me […]

  • August 15, 2019

    C++: Size Matters in Platform Compatibility

    Introduction For file storage and data communication to work interoperably, the width of datatype must stay invariant across platforms. This tip discusses the pitfalls of platform-dependent data width and their solution. Endianess, deserving a tip of its own, is not covered here. time_t time_t stores the number of seconds since 1st January 1970. It is […]

←Previous Page
1 … 3 4 5 6 7 8
Next Page→

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
 

Loading Comments...
 

    • Follow Following
      • Coding Tidbit
      • Already have a WordPress.com account? Log in now.
      • Coding Tidbit
      • Edit Site
      • Follow Following
      • Sign up
      • Log in
      • Report this content
      • View site in Reader
      • Manage subscriptions
      • Collapse this bar