From 50b548899715fbb2757eacc54c5df9443cfa685b Mon Sep 17 00:00:00 2001
From: Beman
Consider this problem:
+ +Add 100 to a big endian value in a file, then write the + result to a file | +|
Endian type approach | +Endian conversion approach | +
+ +big_int32_t x; + +... read into x from a file ... + +x += 100; + +... write x to a file ... ++ |
+
+ +int32_t x; + +... read into x from a file ... + +big_endian(x); +x += 100; +big_endian(x); + +... write x to a file ... ++ |
+
There will be no performance difference between the two approaches. Optimizing compilers will likely +generate exactly the same code for both.
+ +Now consider a slightly different problem:
+ +Add a million values to a big endian value in a file, then write the + result to a file | +|
Endian type approach | +Endian conversion approach | +
+ +big_int32_t x; + +... read into x from a file ... + +for (int32_t i = 0; i < 1000000; ++i) + x += f(i); + +... write x to a file ... ++ |
+
+ +int32_t x; + +... read into x from a file ... + +big_endian(x); + +for (int32_t i = 0; i < 1000000; ++i) + x += f(i); + +big_endian(x); + +... write x to a file ... ++ |
+
There will be no performance difference. Optimizing compilers will likely +generate exactly the same code for both approaches.
+These tests were run against release builds on a circa 2012 4-core little endian X64 Intel Core i5-3570K CPU @ 3.40GHz under Windows 7.
@@ -355,7 +445,7 @@ Tim Blechmann, Tim Moore, tymofey, Tomas Puverle, Vincente Botet, Yuval Ronen and Vitaly Budovski,.Last revised: -25 May, 2013
+26 May, 2013© Copyright Beman Dawes, 2011, 2013
Distributed under the Boost Software License, Version 1.0. See www.boost.org/ LICENSE_1_0.txt
diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index cb65ccc..6353ea4 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -15,6 +15,7 @@ #include