Changes in / [e2ef6bf:7aa78b4]


Ignore:
Location:
doc/generic_types
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/generic_types.tex

    re2ef6bf r7aa78b4  
    938938In fact, \CFA's features for generic programming can enable faster runtime execution than idiomatic @void *@-based C code.
    939939This 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.
     940Since 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.
     941A more illustrative benchmark measures the costs of idiomatic usage of each language's features.
    942942Figure~\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}.
    943943The benchmark test is similar for C and \CC.
     
    978978hence runtime checks are necessary to safely down-cast objects.
    979979The 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.
     980For 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.
    981981Note, the C benchmark uses unchecked casts as there is no runtime mechanism to perform such checks, while \CFA and \CC provide type-safety statically.
    982982
     
    10001000                                                                        & \CT{C}        & \CT{\CFA}     & \CT{\CC}      & \CT{\CCV}             \\ \hline
    10011001maximum memory usage (MB)                       & 10001         & 2502          & 2503          & 11253                 \\
    1002 source code size (lines)                        & 247           & 223           & 165           & 339                   \\
     1002source code size (lines)                        & 247           & 222           & 165           & 339                   \\
    10031003redundant type annotations (lines)      & 39            & 2                     & 2                     & 15                    \\
    10041004binary size (KB)                                        & 14            & 229           & 18            & 38                    \\
     
    10081008The 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;
    10091009this 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.
     1010By 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.
    10111011\CCV is slower than C largely due to the cost of runtime type-checking of down-casts (implemented with @dynamic_cast@);
    10121012There are two outliers in the graph for \CFA: all prints and pop of @pair@.
    10131013Both 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.
     1014A compiler designed for \CFA could easily perform these optimizations.
    10151015Finally, the binary size for \CFA is larger because of static linking with the \CFA libraries.
    10161016
    1017 \CC 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.
     1018On 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;
    10201020with their omission the \CCV line count is similar to C.
    10211021We 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.