Changeset ff29f08 for doc/papers/general/evaluation
- Timestamp:
- May 18, 2018, 2:09:21 PM (8 years ago)
- Branches:
- new-env, with_gc
- Children:
- 2472a19
- Parents:
- f6f0cca3 (diff), c7d8100c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- doc/papers/general/evaluation
- Files:
-
- 15 edited
-
c-bench.c (modified) (3 diffs)
-
c-pair.c (modified) (1 diff)
-
c-pair.h (modified) (1 diff)
-
c-print.c (modified) (1 diff)
-
c-print.h (modified) (1 diff)
-
c-stack.c (modified) (2 diffs)
-
c-stack.h (modified) (1 diff)
-
cfa-stack.c (modified) (1 diff)
-
cfa-stack.h (modified) (1 diff)
-
cpp-stack.hpp (modified) (2 diffs)
-
cpp-vstack.cpp (modified) (2 diffs)
-
cpp-vstack.hpp (modified) (1 diff)
-
timing.dat (modified) (1 diff)
-
timing.gp (modified) (1 diff)
-
timing.xlsx (modified) ( previous)
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/evaluation/c-bench.c
rf6f0cca3 rff29f08 5 5 #include "c-stack.h" 6 6 7 char * new_char( char c ) {8 char* q = malloc( sizeof(char)); /***/7 char * new_char( char c ) { 8 char* q = malloc( sizeof(char) ); /***/ 9 9 *q = c; 10 10 return q; 11 11 } 12 12 13 short * new_short( short s ) {14 short* q = malloc( sizeof(short)); /***/13 short * new_short( short s ) { 14 short* q = malloc( sizeof(short) ); /***/ 15 15 *q = s; 16 16 return q; … … 18 18 19 19 int* new_int( int i ) { 20 int* q = malloc( sizeof(int)); /***/20 int* q = malloc( sizeof(int) ); /***/ 21 21 *q = i; 22 22 return q; 23 23 } 24 24 25 void * copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/26 void * copy_short( const void* p ) { return new_short( *(const short*)p ); } /***/27 void * copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/28 void * copy_pair_short_char( const void* p ) { return copy_pair( p, copy_short, copy_char ); } /***/29 void free_pair_short_char( void * p ) { free_pair( p, free, free ); } /***/25 void * copy_char( const void * p ) { return new_char( *(const char*)p ); } /***/ 26 void * copy_short( const void * p ) { return new_short( *(const short*)p ); } /***/ 27 void * copy_int( const void * p ) { return new_int( *(const int*)p ); } /***/ 28 void * copy_pair_short_char( const void * p ) { return copy_pair( p, copy_short, copy_char ); } /***/ 29 void free_pair_short_char( void * p ) { free_pair( p, free, free ); } /***/ 30 30 31 31 int cmp_char( const void* a, const void* b ) { /***/ … … 37 37 } 38 38 39 int main(int argc, char ** argv) {39 int main(int argc, char * argv[] ) { 40 40 int maxi = 0, vali = 42; 41 41 struct stack si = new_stack(), ti; -
doc/papers/general/evaluation/c-pair.c
rf6f0cca3 rff29f08 2 2 #include "c-pair.h" 3 3 4 struct pair* new_pair(void* first, void* second) {5 struct pair* p = malloc(sizeof(struct pair)); /***/6 *p = ( structpair){ first, second }; /***/4 pair * new_pair( void * first, void * second ) { 5 pair * p = malloc( sizeof(pair) ); /***/ 6 *p = (pair){ first, second }; /***/ 7 7 return p; 8 8 } 9 9 10 struct pair* copy_pair(const struct pair* src,11 void * (*copy_first)(const void*), void* (*copy_second)(const void*)) {10 pair * copy_pair( const pair * src, 11 void * (* copy_first)(const void* ), void * (* copy_second)(const void *)) { 12 12 return new_pair( copy_first(src->first), copy_second(src->second) ); 13 13 } 14 14 15 void free_pair( struct pair* p, void (*free_first)(void*), void (*free_second)(void*)) {16 free_first( p->first);17 free_second( p->second);18 free( p);15 void free_pair( pair * p, void (* free_first)(void *), void (* free_second)(void *)) { 16 free_first( p->first ); 17 free_second( p->second ); 18 free( p ); 19 19 } 20 20 21 int cmp_pair( const struct pair* a, const struct pair* b,22 int (* cmp_first)(const void*, const void*), int (*cmp_second)(const void*, const void*)) {23 int c = cmp_first( a->first, b->first);24 if ( c == 0 ) c = cmp_second( a->second, b->second);21 int cmp_pair( const pair * a, const pair * b, 22 int (* cmp_first)(const void *, const void *), int (* cmp_second)(const void *, const void *)) { 23 int c = cmp_first( a->first, b->first ); 24 if ( c == 0 ) c = cmp_second( a->second, b->second ); 25 25 return c; 26 26 } -
doc/papers/general/evaluation/c-pair.h
rf6f0cca3 rff29f08 1 1 #pragma once 2 2 3 struct pair {4 void * first;5 void * second;6 } ;3 typedef struct pair { 4 void * first; 5 void * second; 6 } pair; 7 7 8 struct pair* new_pair(void* first, void* second);8 pair * new_pair( void * first, void * second ); 9 9 10 struct pair* copy_pair(const struct pair* src,11 void * (*copy_first)(const void*), void* (*copy_second)(const void*));10 pair * copy_pair( const pair * src, 11 void * (* copy_first)(const void *), void * (* copy_second)(const void *)); 12 12 13 void free_pair( struct pair* p, void (*free_first)(void*), void (*free_second)(void*));13 void free_pair( pair * p, void (* free_first)(void *), void (* free_second)(void *)); 14 14 15 int cmp_pair( const struct pair* a, const struct pair* b,16 int (* cmp_first)(const void*, const void*), int (*cmp_second)(const void*, const void*));15 int cmp_pair( const pair * a, const pair * b, 16 int (* cmp_first)(const void *, const void *), int (* cmp_second)(const void *, const void *)); -
doc/papers/general/evaluation/c-print.c
rf6f0cca3 rff29f08 4 4 #include "c-print.h" 5 5 6 void print_string( FILE* out, const char* x) { fprintf(out, "%s", x); }6 void print_string( FILE * out, const char * x ) { fprintf( out, "%s", x ); } 7 7 8 void print_bool( FILE* out, _Bool x) { fprintf(out, "%s", x ? "true" : "false"); }8 void print_bool( FILE * out, _Bool x ) { fprintf( out, "%s", x ? "true" : "false" ); } 9 9 10 void print_char( FILE* out, char x) {11 if ( 0x20 <= x && x <= 0x7E ) { fprintf( out, "'%c'", x); }12 else { fprintf( out, "'\\%x'", x); }10 void print_char( FILE * out, char x ) { 11 if ( 0x20 <= x && x <= 0x7E ) { fprintf( out, "'%c'", x ); } 12 else { fprintf( out, "'\\%x'", x ); } 13 13 } 14 14 15 void print_int( FILE* out, int x) { fprintf(out, "%d", x); }15 void print_int( FILE * out, int x ) { fprintf( out, "%d", x ); } 16 16 17 void print_fmt( FILE* out, char fmt, void* p) {17 void print_fmt( FILE * out, char fmt, void * p ) { 18 18 switch( fmt ) { 19 case 's': print_string( out, (const char*)p); break; /***/20 case 'b': print_bool( out, *(_Bool*)p); break; /***/21 case 'c': print_char( out, *(char*)p); break; /***/22 case 'd': print_int( out, *(int*)p); break; /***/19 case 's': print_string( out, (const char*)p ); break; /***/ 20 case 'b': print_bool( out, *(_Bool*)p ); break; /***/ 21 case 'c': print_char( out, *(char*)p ); break; /***/ 22 case 'd': print_int( out, *(int*)p ); break; /***/ 23 23 } 24 24 } 25 25 26 void print( FILE* out, const char* fmt, ...) {26 void print( FILE * out, const char * fmt, ... ) { 27 27 va_list args; 28 28 va_start(args, fmt); 29 for ( const char* it = fmt; *it; ++it) {29 for ( const char * it = fmt; *it; ++it ) { 30 30 switch( *it ) { 31 case 's': print_string( out, va_arg(args, const char*)); break; /***/32 case 'b': print_bool( out, va_arg(args, int)); break; /***/33 case 'c': print_char( out, va_arg(args, int)); break; /***/34 case 'd': print_int( out, va_arg(args, int)); break; /***/31 case 's': print_string( out, va_arg( args, const char * ) ); break; /***/ 32 case 'b': print_bool( out, va_arg( args, int ) ); break; /***/ 33 case 'c': print_char( out, va_arg( args, int ) ); break; /***/ 34 case 'd': print_int( out, va_arg( args, int ) ); break; /***/ 35 35 case 'p': { 36 const struct pair x = va_arg( args, const struct pair); /***/37 fprintf( out, "[");38 print_fmt( out, *++it, x.first); /***/39 fprintf( out, ", ");40 print_fmt( out, *++it, x.second); /***/41 fprintf( out, "]");36 const struct pair x = va_arg( args, const struct pair ); /***/ 37 fprintf( out, "[" ); 38 print_fmt( out, *++it, x.first ); /***/ 39 fprintf( out, ", " ); 40 print_fmt( out, *++it, x.second ); /***/ 41 fprintf( out, "]" ); 42 42 break; 43 43 } 44 44 } 45 45 } 46 va_end( args);46 va_end( args ); 47 47 } -
doc/papers/general/evaluation/c-print.h
rf6f0cca3 rff29f08 2 2 #include <stdio.h> 3 3 4 void print_string( FILE* out, const char* x);5 void print_bool( FILE* out, _Bool x);6 void print_char( FILE* out, char x);7 void print_int( FILE* out, int x);4 void print_string( FILE * out, const char * x ); 5 void print_bool( FILE * out, _Bool x ); 6 void print_char( FILE * out, char x ); 7 void print_int( FILE * out, int x ); 8 8 9 void print( FILE* out, const char* fmt, ...);9 void print( FILE * out, const char * fmt, ... ); -
doc/papers/general/evaluation/c-stack.c
rf6f0cca3 rff29f08 2 2 #include "c-stack.h" 3 3 4 struct stack_node {4 typedef struct node { 5 5 void * value; 6 struct stack_node * next;7 } ;6 struct node * next; 7 } node; 8 8 9 void clear_stack( struct stack * s, void (*free_el)( void * ) ) { 10 for ( struct stack_node * next = s->head; next; ) { 11 struct stack_node * crnt = next; 12 next = crnt->next; 13 free_el( crnt->value ); 14 free( crnt ); 9 void copy_stack( stack * s, const stack * t, void * (*copy)( const void * ) ) { 10 node ** cr = &s->head; 11 for ( node * nx = t->head; nx; nx = nx->next ) { 12 *cr = malloc( sizeof(node) ); /***/ 13 (*cr)->value = copy( nx->value ); 14 cr = &(*cr)->next; 15 } 16 *cr = NULL; 17 } 18 19 void clear_stack( stack * s, void (* free_el)( void * ) ) { 20 for ( node * nx = s->head; nx; ) { 21 node * cr = nx; 22 nx = cr->next; 23 free_el( cr->value ); 24 free( cr ); 15 25 } 16 26 s->head = NULL; 17 27 } 18 28 19 struct stack new_stack() { return (struct stack){ NULL }; /***/ } 29 stack new_stack() { 30 return (stack){ NULL }; /***/ 31 } 20 32 21 void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) { 22 struct stack_node ** crnt = &s->head; 23 for ( struct stack_node * next = t->head; next; next = next->next ) { 24 *crnt = malloc( sizeof(struct stack_node) ); /***/ 25 (*crnt)->value = copy( next->value ); 26 crnt = &(*crnt)->next; 27 } 28 *crnt = NULL; 29 } 30 struct stack * assign_stack( struct stack * s, const struct stack * t, 33 stack * assign_stack( stack * s, const stack * t, 31 34 void * (*copy_el)( const void * ), void (*free_el)( void * ) ) { 32 35 if ( s->head == t->head ) return s; … … 36 39 } 37 40 38 _Bool stack_empty( const struct stack * s ) { return s->head == NULL; } 41 _Bool stack_empty( const stack * s ) { 42 return s->head == NULL; 43 } 39 44 40 void push_stack( st ruct stack * s, void * v ) {41 struct stack_node * n = malloc( sizeof(struct stack_node) ); /***/42 *n = ( struct stack_node){ v, s->head }; /***/45 void push_stack( stack * s, void * v ) { 46 node * n = malloc( sizeof(node) ); /***/ 47 *n = (node){ v, s->head }; /***/ 43 48 s->head = n; 44 49 } 45 50 46 void * pop_stack( st ruct stack * s ) {47 struct stack_node * n = s->head;51 void * pop_stack( stack * s ) { 52 node * n = s->head; 48 53 s->head = n->next; 49 54 void * v = n->value; -
doc/papers/general/evaluation/c-stack.h
rf6f0cca3 rff29f08 1 1 #pragma once 2 2 3 struct stack_node;4 struct stack {5 struct stack_node* head;6 } ;3 struct node; 4 typedef struct stack { 5 struct node * head; 6 } stack; 7 7 8 struct stack new_stack();9 void c opy_stack(struct stack* dst, const struct stack* src, void* (*copy)(const void*));10 st ruct stack* assign_stack(struct stack* dst, const struct stack* src,11 void* (*copy_el)(const void*), void (*free_el)(void*)); 12 void clear_stack(struct stack* s, void (*free_el)(void*));8 void copy_stack(stack * dst, const stack * src, void * (* copy)(const void *)); 9 void clear_stack(stack * s, void (*free_el)(void *)); 10 stack new_stack(); 11 stack * assign_stack( stack * dst, const stack * src, 12 void * (* copy_el)(const void *), void (* free_el)(void *)); 13 13 14 _Bool stack_empty( const struct stack* s);15 void push_stack( struct stack* s, void* value);16 void * pop_stack(struct stack* s);14 _Bool stack_empty( const stack * s ); 15 void push_stack( stack * s, void * value ); 16 void * pop_stack( stack * s ); -
doc/papers/general/evaluation/cfa-stack.c
rf6f0cca3 rff29f08 2 2 #include "cfa-stack.h" 3 3 4 forall( otype T ) struct stack_node { 5 T value; 6 stack_node(T) * next; 7 }; 4 forall( otype T ) { 5 struct node { 6 T value; 7 node(T) * next; 8 }; 8 9 9 forall( otype T ) void clear( stack(T) & s ) with( s ) { 10 for ( stack_node(T) * next = head; next; ) { 11 stack_node(T) * crnt = next; 12 next = crnt->next; 13 ^(*crnt){}; 14 free(crnt); 10 void ?{}( stack(T) & s, stack(T) t ) { // copy 11 node(T) ** cr = &s.head; 12 for ( node(T) * nx = t.head; nx; nx = nx->next ) { 13 *cr = alloc(); 14 ((*cr)->value){ nx->value }; 15 cr = &(*cr)->next; 16 } 17 *cr = 0; 15 18 } 16 head = 0; 19 20 void clear( stack(T) & s ) with( s ) { 21 for ( node(T) * nx = head; nx; ) { 22 node(T) * cr = nx; 23 nx = cr->next; 24 ^(*cr){}; 25 free( cr ); 26 } 27 head = 0; 28 } 29 30 void ?{}( stack(T) & s ) { (s.head){ 0 }; } 31 void ^?{}( stack(T) & s) { clear( s ); } 32 33 stack(T) ?=?( stack(T) & s, stack(T) t ) { 34 if ( s.head == t.head ) return s; 35 clear( s ); 36 s{ t }; 37 return s; 38 } 39 40 _Bool empty( const stack(T) & s ) { 41 return s.head == 0; 42 } 43 44 void push( stack(T) & s, T value ) with( s ) { 45 node(T) * n = alloc(); 46 (*n){ value, head }; 47 head = n; 48 } 49 50 T pop( stack(T) & s ) with( s ) { 51 node(T) * n = head; 52 head = n->next; 53 T v = n->value; 54 ^(*n){}; 55 free( n ); 56 return v; 57 } 17 58 } 18 19 forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }20 21 forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) {22 stack_node(T) ** crnt = &s.head;23 for ( stack_node(T) * next = t.head; next; next = next->next ) {24 *crnt = alloc();25 ((*crnt)->value){ next->value };26 crnt = &(*crnt)->next;27 }28 *crnt = 0;29 }30 31 forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t ) {32 if ( s.head == t.head ) return s;33 clear( s );34 s{ t };35 return s;36 }37 38 forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }39 40 forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; }41 42 forall( otype T ) void push( stack(T) & s, T value ) with( s ) {43 stack_node(T) * n = alloc();44 (*n){ value, head };45 head = n;46 }47 48 forall( otype T ) T pop( stack(T) & s ) with( s ) {49 stack_node(T) * n = head;50 head = n->next;51 T v = n->value;52 ^(*n){};53 free( n );54 return v;55 } -
doc/papers/general/evaluation/cfa-stack.h
rf6f0cca3 rff29f08 1 1 #pragma once 2 2 3 forall( otype T ) struct stack_node; 4 forall( otype T ) struct stack { 5 stack_node(T) * head; 6 }; 3 forall( otype T ) { 4 struct node; 5 struct stack { 6 node(T) * head; 7 }; 7 8 8 forall( otype T ) void ?{}( stack(T) & s);9 forall( otype T ) void ?{}( stack(T) & s, stack(T) t);10 forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t);11 forall( otype T )void ^?{}( stack(T) & s);9 void ?{}( stack(T) & s, stack(T) t ); 10 void clear( stack(T) & s ); 11 void ?{}( stack(T) & s ); 12 void ^?{}( stack(T) & s); 12 13 13 forall( otype T ) _Bool empty( const stack(T) & s ); 14 forall( otype T ) void push( stack(T) & s, T value ); 15 forall( otype T ) T pop( stack(T) & s ); 16 forall( otype T ) void clear( stack(T) & s ); 14 stack(T) ?=?( stack(T) & s, stack(T) t ); 15 _Bool empty( const stack(T) & s ); 16 void push( stack(T) & s, T value ); 17 T pop( stack(T) & s ); 18 } -
doc/papers/general/evaluation/cpp-stack.hpp
rf6f0cca3 rff29f08 10 10 node * head; 11 11 12 stack() : head( nullptr ) {} 13 stack( const stack<T> & o ) { copy( o ); } 12 void copy( const stack<T> & o ) { 13 node ** cr = &head; 14 for ( node * nx = o.head; nx; nx = nx->next ) { 15 *cr = new node{ nx->value }; /***/ 16 cr = &(*cr)->next; 17 } 18 *cr = nullptr; 19 } 14 20 15 21 void clear() { 16 for ( node * n ext = head; next; ) {17 node * cr nt = next;18 n ext = crnt->next;19 delete cr nt;22 for ( node * nx = head; nx; ) { 23 node * cr = nx; 24 nx = cr->next; 25 delete cr; 20 26 } 21 27 head = nullptr; 22 28 } 23 29 24 void copy( const stack<T> & o ) { 25 node ** crnt = &head; 26 for ( node * next = o.head; next; next = next->next ) { 27 *crnt = new node{ next->value }; /***/ 28 crnt = &(*crnt)->next; 29 } 30 *crnt = nullptr; 31 } 32 30 stack() : head( nullptr ) {} 31 stack( const stack<T> & o ) { copy( o ); } 33 32 ~stack() { clear(); } 34 33 35 stack & operator= ( const stack<T> & o ) {34 stack & operator=( const stack<T> & o ) { 36 35 if ( this == &o ) return *this; 37 36 clear(); … … 40 39 } 41 40 42 bool empty() const { return head == nullptr; } 41 bool empty() const { 42 return head == nullptr; 43 } 43 44 44 void push( const T & value ) { head = new node{ value, head }; /***/ } 45 void push( const T & value ) { 46 head = new node{ value, head }; /***/ 47 } 45 48 46 49 T pop() { -
doc/papers/general/evaluation/cpp-vstack.cpp
rf6f0cca3 rff29f08 4 4 stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {} 5 5 6 void stack::copy( const stack & o ) { 7 node ** cr = &head; 8 for ( node * nx = o.head; nx; nx = nx->next ) { 9 *cr = new node{ *nx->value }; /***/ 10 cr = &(*cr)->next; 11 } 12 *cr = nullptr; 13 } 14 6 15 void stack::clear() { 7 for ( node * n ext = head; next; ) {8 node * cr nt = next;9 n ext = crnt->next;10 delete cr nt;16 for ( node * nx = head; nx; ) { 17 node * cr = nx; 18 nx = cr->next; 19 delete cr; 11 20 } 12 21 head = nullptr; 13 }14 15 void stack::copy( const stack & o ) {16 node ** crnt = &head;17 for ( node * next = o.head; next; next = next->next ) {18 *crnt = new node{ *next->value }; /***/19 crnt = &(*crnt)->next;20 }21 *crnt = nullptr;22 22 } 23 23 … … 33 33 } 34 34 35 bool stack::empty() const { return head == nullptr; } 35 bool stack::empty() const { 36 return head == nullptr; 37 } 36 38 37 void stack::push( const object & value ) { head = new node{ value, head }; /***/ } 39 void stack::push( const object & value ) { 40 head = new node{ value, head }; /***/ 41 } 38 42 39 43 ptr<object> stack::pop() { -
doc/papers/general/evaluation/cpp-vstack.hpp
rf6f0cca3 rff29f08 10 10 node * head; 11 11 12 void copy( const stack & o ); 12 13 void clear(); 13 void copy( const stack & o );14 14 15 15 stack(); -
doc/papers/general/evaluation/timing.dat
rf6f0cca3 rff29f08 1 1 "400 million repetitions" "C" "\\CFA{}" "\\CC{}" "\\CC{obj}" 2 "push\nint" 3002 2459 1542 3269 3 "copy\nint" 2985 2057 1539 3083 4 "clear\nint" 1374 827 756 1469 5 "pop\nint" 1416 1221 760 5098 6 "push\npair" 4214 2752 950 6873 7 "copy\npair" 6127 2105 987 7293 8 "clear\npair" 2881 885 751 3460 9 "pop\npair" 3046 5434 822 24962 2 "push\nint" 2911 2034 1504 3246 3 "copy\nint" 2953 1622 1526 3075 4 "clear\nint" 1397 754 753 1452 5 "pop\nint" 1446 1203 760 5016 6 "push\npair" 3673 2297 955 6971 7 "copy\npair" 6027 1183 998 7204 8 "clear\npair" 2840 773 748 3511 9 "pop\npair" 3025 5414 813 23867 10 -
doc/papers/general/evaluation/timing.gp
rf6f0cca3 rff29f08 24 24 set yrange [0:10] 25 25 26 set label "2 5.0" at 7.125,10.527 26 set label "23.9" at 7.125,10.5 27 set style fill pattern 4 border lt -1 28 28 # set datafile separator "," 29 29 plot for [COL=2:5] 'evaluation/timing.dat' using (column(COL)/SCALE):xticlabels(1) title columnheader
Note:
See TracChangeset
for help on using the changeset viewer.