Changes in / [e2ef6bf:7aa78b4]
- Location:
- doc/generic_types
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/generic_types.tex
re2ef6bf r7aa78b4 938 938 In fact, \CFA's features for generic programming can enable faster runtime execution than idiomatic @void *@-based C code. 939 939 This claim is demonstrated through a set of generic-code-based micro-benchmarks in C, \CFA, and \CC (see stack implementations in Appendix~\ref{sec:BenchmarkStackImplementation}). 940 Since all these languages share a subset comprising standard C, maximal-performance benchmarks would show little runtime variance, other than in length and clarity of source code.941 A more illustrative benchmark is the idiomatic costs of each language's features covering common usage.940 Since all these languages share a subset essentially comprising standard C, maximal-performance benchmarks would show little runtime variance, other than in length and clarity of source code. 941 A more illustrative benchmark measures the costs of idiomatic usage of each language's features. 942 942 Figure~\ref{fig:BenchmarkTest} shows the \CFA benchmark tests for a generic stack based on a singly linked-list, a generic pair-data-structure, and a variadic @print@ routine similar to that in Section~\ref{sec:variadic-tuples}. 943 943 The benchmark test is similar for C and \CC. … … 978 978 hence runtime checks are necessary to safely down-cast objects. 979 979 The most notable difference among the implementations is in memory layout of generic types: \CFA and \CC inline the stack and pair elements into corresponding list and pair nodes, while C and \CCV lack such a capability and instead must store generic objects via pointers to separately-allocated objects. 980 For the print benchmark, idiomatic printing is used: the C and \CFA variants used @stdio.h@, while the \CC and \CCV variants used @iostream@; preliminary tests show this distinction has little runtime impact.980 For the print benchmark, idiomatic printing is used: the C and \CFA variants used @stdio.h@, while the \CC and \CCV variants used @iostream@; preliminary tests show this distinction has negligible runtime impact. 981 981 Note, the C benchmark uses unchecked casts as there is no runtime mechanism to perform such checks, while \CFA and \CC provide type-safety statically. 982 982 … … 1000 1000 & \CT{C} & \CT{\CFA} & \CT{\CC} & \CT{\CCV} \\ \hline 1001 1001 maximum memory usage (MB) & 10001 & 2502 & 2503 & 11253 \\ 1002 source code size (lines) & 247 & 22 3& 165 & 339 \\1002 source code size (lines) & 247 & 222 & 165 & 339 \\ 1003 1003 redundant type annotations (lines) & 39 & 2 & 2 & 15 \\ 1004 1004 binary size (KB) & 14 & 229 & 18 & 38 \\ … … 1008 1008 The C and \CCV variants are generally the slowest with the largest memory footprint, because of their less-efficient memory layout and the pointer-indirection necessary to implement generic types; 1009 1009 this inefficiency is exacerbated by the second level of generic types in the pair-based benchmarks. 1010 By contrast, the \CFA and \CC variants run in roughly equivalent time for both the integer and pair of @_Bool@ and @char@ because the storage layout is equivalent .1010 By contrast, the \CFA and \CC variants run in roughly equivalent time for both the integer and pair of @_Bool@ and @char@ because the storage layout is equivalent, with the inlined libraries (\ie no separate compilation) and greater maturity of the \CC compiler contributing to its lead. 1011 1011 \CCV is slower than C largely due to the cost of runtime type-checking of down-casts (implemented with @dynamic_cast@); 1012 1012 There are two outliers in the graph for \CFA: all prints and pop of @pair@. 1013 1013 Both of these cases result from the complexity of the C-generated polymorphic code, so that the GCC compiler is unable to optimize some dead code and condense nested calls. 1014 A compiler for \CFA could easily perform these optimizations.1014 A compiler designed for \CFA could easily perform these optimizations. 1015 1015 Finally, the binary size for \CFA is larger because of static linking with the \CFA libraries. 1016 1016 1017 \C C performs best because it uses header-only inlined libraries (\ie no separate compilation).1018 \CFA and \CC have the advantage of a pre-written generic @pair@ and @stack@ type to reduce line count, while C and \CCV require it to written by the programmer, as C does not have a generic collections-library and \CCV does not use the \CC standard template library by construction.1019 For \CCV, the definition of @object@ and wrapper classes for @bool@, @char@, @int@, and @const char *@ are included in the line count, which inflates its line count, as an actual object-oriented language would include these in the standard library; 1017 \CFA is also competitive in terms of source code size, measured as a proxy for programmer effort. The line counts in Table~\ref{tab:eval} include implementations of @pair@ and @stack@ types for all four languages for purposes of direct comparison, though it should be noted that \CFA and \CC have pre-written data structures in their standard libraries that programmers would generally use instead. Use of these standard library types has minimal impact on the performance benchmarks, but shrinks the \CFA and \CC benchmarks to 73 and 54 lines, respectively. 1018 On the other hand, C does not have a generic collections-library in its standard distribution, resulting in frequent reimplementation of such collection types by C programmers. 1019 \CCV does not use the \CC standard template library by construction, and in fact includes the definition of @object@ and wrapper classes for @bool@, @char@, @int@, and @const char *@ in its line count, which inflates this count somewhat, as an actual object-oriented language would include these in the standard library; 1020 1020 with their omission the \CCV line count is similar to C. 1021 1021 We justify the given line count by noting that many object-oriented languages do not allow implementing new interfaces on library types without subclassing or wrapper types, which may be similarly verbose.
Note: See TracChangeset
for help on using the changeset viewer.