Changeset bbe856c for doc/generic_types
- Timestamp:
- Apr 14, 2017, 5:03:36 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1504536
- Parents:
- 3895b8b5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/generic_types.tex
r3895b8b5 rbbe856c 954 954 Since 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. 955 955 Instead, the presented benchmarks show the costs of idiomatic use of each language's features to examine common usage. 956 The 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}. 956 Figure~\ref{fig:MicroBenchmark} shows the 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 experiments are: 958 \begin{enumerate} 959 \item 960 N stack pushes of int, where N = 40M 961 \item 962 copy int stack 963 \item 964 clear int stack 965 \item 966 N stack pops of int 967 \end{enumerate} 957 968 The 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. 958 969 The \CCV variant illustrates an alternative object-oriented idiom where all objects inherit from a base @object@ class, mimicking a Java-like interface; … … 962 973 Preliminary tests show the difference has little runtime effect. 963 974 Finally, the C @rand@ function is used generate random numbers. 975 976 \begin{figure} 977 \begin{lstlisting}[xleftmargin=3\parindentlnth,aboveskip=0pt,belowskip=0pt,numbers=left,numberstyle=\tt\small,numberblanklines=false] 978 int main( int argc, char *argv[] ) { 979 int max = 0; 980 stack(int) s, t; 981 REPEAT_TIMED( "push_int", push( &s, 42 ); ) 982 TIMED( "copy_int", t = s; ) 983 TIMED( "clear_int", clear( &s ); ) 984 REPEAT_TIMED( "pop_int", max = max( max, pop( &t ) ); ) 985 986 stack(pair(_Bool, char)) s, t; 987 pair(_Bool, char) max = { (_Bool)0, '\0' }; 988 REPEAT_TIMED( "push_pair", push( &s, (pair(_Bool, char)){ 42, 42 } ); ) 989 TIMED( "copy_pair", t = s; ) 990 TIMED( "clear_pair", clear( &s ); ) 991 REPEAT_TIMED( "pop_pair", max = max( max, pop( &t ) ); ) 992 993 FILE * out = fopen( "cfa-out.txt", "w" ); 994 REPEAT_TIMED( "print_int", print( out, 42, ":", 42, "\n" ); ) 995 REPEAT_TIMED( "print_pair", 996 print( out, (pair(_Bool, char)){ 42, 42 }, ":", (pair(_Bool, char)){ 42, 42 }, "\n" ); ) 997 fclose(out); 998 } 999 \end{lstlisting} 1000 \caption{Micro-Benchmark} 1001 \label{fig:MicroBenchmark} 1002 \end{figure} 964 1003 965 1004 \begin{figure} … … 1050 1089 SETL~\cite{SETL} is a high-level mathematical programming language, with tuples being one of the primary data types. 1051 1090 Tuples in SETL allow subscripting, dynamic expansion, and multiple assignment. 1052 C provides variadic functions through @va_list@ objects, but the programmer is responsible for managing the number of arguments and their types .1091 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. 1053 1092 KW-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. 1054 1093 The main contributions of that work were adding MRVF, tuple mass and multiple assignment, and record-field access.
Note: See TracChangeset
for help on using the changeset viewer.