Changes in / [4570131:e3de500]


Ignore:
Location:
doc/generic_types
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/evaluation/timing.gp

    r4570131 re3de500  
    1212set boxwidth 0.8
    1313
     14set ylabel "milliseconds"
    1415set key top left reverse Left
    1516
     
    2021set linetype 4 lc rgb 'green'
    2122
    22 set ylabel "milli-seconds"
    23 set yrange [0:*] ;
    24 
    2523set datafile separator ","
    2624plot for [COL=2:5] 'evaluation/timing.csv' using COL:xticlabels(1) title columnheader
  • doc/generic_types/generic_types.tex

    r4570131 re3de500  
    954954Since all these languages share a subset comprising most of standard C, maximal-performance benchmarks would show little runtime variance, other than in length and clarity of source code.
    955955Instead, the presented benchmarks show the costs of idiomatic use of each language's features to examine common usage.
    956 Figure~\ref{fig:MicroBenchmark} 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}.
    957 The tests are similar for C and \CC.
    958 The first two experiments use element types @int@ and @pair( _Bool, char)@, and push $N=40M$ elements on a generic stack, copy the stack, clear one of the stacks, and find the maximum value in the other stack.
    959 The last experiment creates a file and prints $N=40M$ elements of type @int@ and @pair( _Bool, char)@ using a variadic print.
    960 
     956The benchmarks test 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}.
    961957The structure of each implemented is: C with @void *@-based polymorphism, \CFA with the different presented features, \CC with templates, and \CC using only class inheritance for polymorphism, called \CCV.
    962958The \CCV variant illustrates an alternative object-oriented idiom where all objects inherit from a base @object@ class, mimicking a Java-like interface;
    963959hence runtime checks are necessary to safely down-cast objects.
    964 The most notable difference among the implementations is in optimizations: \CFA and \CC inline the stack and pair elements into corresponding list and pair nodes, while the C and \CCV lack generic-type capability {\color{red}(AWKWARD) to store generic objects via pointers to separately-allocated objects}.
    965 For the print benchmark, idiomatic printing is used: the C and \CFA variants used @cstdio.h@, while the \CC and \CCV variants used @iostream@.
    966 Preliminary tests show the difference has little runtime effect.
     960The 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 store generic objects via pointers to separately-allocated objects instead.
     961For the print benchmark, idiomatic printing is used: the C and \CFA variants use @stdio.h@, while the \CC and \CCV variants use @iostream@.
     962Preliminary tests show this difference has little runtime effect.
    967963Finally, the C @rand@ function is used generate random numbers.
    968 
    969 \begin{figure}
    970 \begin{lstlisting}[xleftmargin=3\parindentlnth,aboveskip=0pt,belowskip=0pt,numbers=left,numberstyle=\tt\small,numberblanklines=false]
    971 int main( int argc, char *argv[] ) {
    972         int max = 0;
    973         stack(int) s, t;
    974         REPEAT_TIMED( "push_int", push( &s, 42 ); )
    975         TIMED( "copy_int", t = s; )
    976         TIMED( "clear_int", clear( &s ); )
    977         REPEAT_TIMED( "pop_int", max = max( max, pop( &t ) ); )
    978 
    979         stack(pair(_Bool, char)) s1, t1;
    980         pair(_Bool, char) max = { (_Bool)0, '\0' };
    981         REPEAT_TIMED( "push_pair", push( &s1, (pair(_Bool, char)){ (_Bool)0, 'a' } ); )
    982         TIMED( "copy_pair", t1 = s1; )
    983         TIMED( "clear_pair", clear( &s1 ); )
    984         REPEAT_TIMED( "pop_pair", max = max( max, pop( &t1 ) ); )
    985 
    986         FILE * out = fopen( "cfa-out.txt", "w" );
    987         REPEAT_TIMED( "print_int", print( out, 42, ":", 42, "\n" ); )
    988         REPEAT_TIMED( "print_pair", print( out, (pair(_Bool, char)){ (_Bool)0, 'a' }, ":",
    989                                                          (pair(_Bool, char)){ (_Bool)0, 'a' }, "\n" ); )
    990         fclose(out);
    991 }
    992 \end{lstlisting}
    993 \caption{Micro-Benchmark}
    994 \label{fig:MicroBenchmark}
    995 \end{figure}
    996964
    997965\begin{figure}
     
    1007975\newcommand{\CT}[1]{\multicolumn{1}{c}{#1}}
    1008976\begin{tabular}{r|rrrr}
    1009                                                         & \CT{C}        & \CT{\CFA}     & \CT{\CC}      &       \CT{\CCV}       \\ \hline
    1010 maximum memory usage (MB)       & 10001         & 2501          & 2503          &       11253           \\
    1011 source code size (lines)        & 301           & 224           & 188           &       437                     \\
     977                                                                        & \CT{C}        & \CT{\CFA}     & \CT{\CC}      &       \CT{\CCV}       \\ \hline
     978maximum memory usage (MB)                       & 10001         & 2501          & 2503          &       11253           \\
     979source code size (lines)                        & 301           & 224           & 188           &       437                     \\
    1012980redundant type annotations (lines)      & 46            & 3                     & 2                     &       15                      \\
    1013 binary size (KB)                        & 18            & 234           & 18            &       42                      \\
     981binary size (KB)                                        & 18            & 234           & 18            &       42                      \\
    1014982\end{tabular}
    1015983\end{table}
     
    10831051SETL~\cite{SETL} is a high-level mathematical programming language, with tuples being one of the primary data types.
    10841052Tuples in SETL allow subscripting, dynamic expansion, and multiple assignment.
    1085 C provides variadic functions through @va_list@ objects, but the programmer is responsible for managing the number of arguments and their types, so the mechanism is not type-safe.
     1053C provides variadic functions through @va_list@ objects, but the programmer is responsible for managing the number of arguments and their types.
    10861054KW-C~\cite{Buhr94a}, a predecessor of \CFA, introduced tuples to C as an extension of the C syntax, taking much of its inspiration from SETL.
    10871055The main contributions of that work were adding MRVF, tuple mass and multiple assignment, and record-field access.
     
    11191087
    11201088
     1089\appendix
     1090
     1091\section{BenchMarks}
     1092\label{sec:BenchMarks}
     1093
     1094TODO
     1095
     1096
    11211097\bibliographystyle{ACM-Reference-Format}
    11221098\bibliography{cfa}
    1123 
    1124 
    1125 \appendix
    1126 
    1127 
    1128 \section{BenchMarks}
    1129 \label{sec:BenchMarks}
    1130 
    1131 TODO
    11321099
    11331100\end{document}
Note: See TracChangeset for help on using the changeset viewer.