Skip to content

Instantly share code, notes, and snippets.

@abeaumont
Created March 28, 2013 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abeaumont/5261596 to your computer and use it in GitHub Desktop.
Save abeaumont/5261596 to your computer and use it in GitHub Desktop.
dispatching benchmark in Dylan
module: dispatch-benchmarks
define open abstract class <my-collection> (<object>)
end class <my-collection>;
define open generic my-element (collection :: <my-collection>, n :: <integer>) => (nth :: <object>);
define method my-element
(collection :: <my-collection>, n :: <integer>)
=> (nth :: <object>)
#f;
end method my-element;
define open abstract class <my-explicit-key-collection> (<my-collection>)
end class <my-explicit-key-collection>;
define method my-element
(collection :: <my-explicit-key-collection>, n :: <integer>)
=> (nth :: <object>)
#f;
end method my-element;
define open abstract class <my-mutable-collection> (<my-collection>)
end class <my-mutable-collection>;
define method my-element
(collection :: <my-mutable-collection>, n :: <integer>)
=> (nth :: <object>)
#f;
end method my-element;
define open abstract class <my-sequence> (<my-collection>)
end class <my-sequence>;
define method my-element
(collection :: <my-sequence>, n :: <integer>)
=> (nth :: <object>)
#f;
end method my-element;
define open abstract class <my-stretchy-collection> (<my-collection>)
end class <my-stretchy-collection>;
define method my-element
(collection :: <my-stretchy-collection>, n :: <integer>)
=> (nth :: <object>)
#f;
end method my-element;
define open abstract class <my-mutable-explicit-key-collection> (<my-explicit-key-collection>, <my-mutable-collection>)
end class <my-mutable-explicit-key-collection>;
define open abstract class <my-mutable-sequence> (<my-mutable-collection>, <my-sequence>)
end class <my-mutable-sequence>;
define sealed class <my-range> (<my-sequence>)
end class <my-range>;
define open abstract class <my-table> (<my-stretchy-collection>, <my-mutable-explicit-key-collection>)
end class <my-table>;
define open abstract class <my-array> (<my-mutable-sequence>)
end class <my-array>;
define sealed abstract class <my-list> (<my-mutable-sequence>)
end class <my-list>;
define abstract class <my-deque> (<my-mutable-sequence>, <my-stretchy-collection>)
end class <my-deque>;
define abstract class <my-string> (<my-mutable-sequence>)
end class <my-string>;
define sealed class <my-empty-list> (<my-list>)
end class <my-empty-list>;
define sealed class <my-pair> (<my-list>)
end class <my-pair>;
define open abstract class <my-vector> (<my-array>)
end class <my-vector>;
define open abstract class <my-stretchy-vector> (<my-stretchy-collection>, <my-vector>)
end class <my-stretchy-vector>;
define sealed class <my-simple-vector> (<my-vector>)
end class <my-simple-vector>;
define sealed class <my-simple-object-vector> (<my-simple-vector>)
end class <my-simple-object-vector>;
define sealed class <no-collection> (<object>)
end class <no-collection>;
define function no-element
(no-collection :: <no-collection>, n :: <integer>)
=> (nth :: <object>)
#f;
end function no-element;
define function my-element-loop(n :: <integer>)
let item = make(<no-collection>);
profiling (cpu-time-seconds, cpu-time-microseconds)
for (i from 1 to n)
no-element(item, 1);
end for;
results
format-out("%s of %d: took %d.%s seconds\n", item.object-class.debug-name,
n, cpu-time-seconds,
integer-to-string(cpu-time-microseconds, size: 3));
end profiling;
let item = make(<my-simple-object-vector>);
profiling (cpu-time-seconds, cpu-time-microseconds)
for (i from 1 to n)
my-element(item, 1);
end for;
results
format-out("%s of %d: took %d.%s seconds\n", item.object-class.debug-name,
n, cpu-time-seconds,
integer-to-string(cpu-time-microseconds, size: 3));
end profiling;
end function my-element-loop;
define function main (name :: <string>, arguments :: <vector>)
let n = string-to-integer(element(arguments, 0, default: "1"));
my-element-loop(n);
exit-application(0);
end function main;
main(application-name(), application-arguments());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment