| <<O>> Difference Topic TreeVisitorIntermediateExample (r1.3 - 24 Dec 2003 - IsaacGouy) |
| Changed: | |
| < < | dispatchTest(this@Tree) { } |
| > > | dispatchTest(Tree this) { } |
| Changed: | |
| < < | dispatchTest(this@Interior) { |
| > > | dispatchTest(Interior this) { |
| Changed: | |
| < < | size(t@Tree) = 1; |
| > > | size(Tree t) = 1; |
| Changed: | |
| < < | size(t@Interior) = 1 + t.getLeft().size() + t.getRight().size(); |
| > > | size(Interior t) = 1 + t.getLeft().size() + t.getRight().size(); |
| Changed: | |
| < < | prettyPrint(t@Tree) = t.prettyPrint( "" ); |
| > > | prettyPrint(Tree t) = t.prettyPrint( "" ); |
| Changed: | |
| < < | prettyPrint(t@Tree, prefix) = prefix + t.value() + "\n"; |
| > > | prettyPrint(Tree t, prefix) = prefix + t.value() + "\n"; |
| Changed: | |
| < < | prettyPrint(t@Interior, prefix) { |
| > > | prettyPrint(Interior t, prefix) { |
| <<O>> Difference Topic TreeVisitorIntermediateExample (r1.2 - 05 Sep 2003 - IsaacGouy) |
| Changed: | |||||||||||||||||
| < < | Tree and Interior represent a simple binary tree; which is extended with a subclass representing n-ary trees and 3 separate external methods ExtendedTreeVisitorIntermediateExample. | ||||||||||||||||
| > > |
The original MultiJava code for this benchmark, and the Java comparison code, is available from this Technical Report:
"MultiJava: Design, implementation, and evaluation of a Java-compatible language supporting modular open classes and symmetric multiple dispatch", Curtis Clifton, Iowa State University TR #01-10, November 2001. ftp://ftp.cs.iastate.edu/pub/techreprts/TR01-10/TR.pdf | ||||||||||||||||
| Added: | |||||||||||||||||
| > > | Curtis Clifton kindly gave permission for this use. | ||||||||||||||||
| Added: | |||||||||||||||||
| > > |
The benchmark results are similar to MultiJava. The Java Extensible Visitor pattern requires much more code, and more complex code, than Nice. The performance of the Java Extensible Visitor implementation degrades from the simple tree walk to the simple size calculation. For the slightly less-simple pretty print method the performance is worse than Nice.
Tree Walk | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < | // compilation unit Tree.nice | ||||||||||||||||
| > > | // compilation unit dispatchTest.nice - Tree Walk | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < |
public class Tree | ||||||||||||||||
| > > |
| ||||||||||||||||
| Changed: | |||||||||||||||||
| < < | // internal implementation of prettyPrinting to // measure regular dispatch speed | ||||||||||||||||
| > > | dispatchTest(this@Tree) { } | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < | // Unlike MultiJava?, in Nice there's no difference // to methods defined externally - like prettyPrint | ||||||||||||||||
| > > | dispatchTest(this@Interior) { this.getLeft().dispatchTest(); this.getRight().dispatchTest(); } | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < | public String internalPrettyPrint(String prefix); internalPrettyPrint(prefix) = prefix + this.getValue().toString + "\n"; | ||||||||||||||||
| > > |
| ||||||||||||||||
| Changed: | |||||||||||||||||
| < < | public String internalPrettyPrint(); internalPrettyPrint() = this.internalPrettyPrint(""); | ||||||||||||||||
| > > |
Size | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < | public !T getValue() = value; } | ||||||||||||||||
| > > |
// compilation unit size.nice package openclassdispatch; <T> int size(Tree<T> t); size(t@Tree) = 1; size(t@Interior) = 1 + t.getLeft().size() + t.getRight().size(); | ||||||||||||||||
| Added: | |||||||||||||||||
| > > |
Pretty Print | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < | // compilation unit Interior.nice | ||||||||||||||||
| > > | / compilation unit prettyPrint.nice | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < |
public class Interior | ||||||||||||||||
| > > |
public | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < | // internal implementation of prettyPrinting to // measure regular dispatch speed | ||||||||||||||||
| > > | prettyPrint(t@Tree) = t.prettyPrint( "" ); | ||||||||||||||||
| Deleted: | |||||||||||||||||
| < < | // Unlike MultiJava?, in Nice there's no difference // to methods defined externally - like prettyPrint | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < | internalPrettyPrint(prefix) { let result = new StringBuffer?( prefix + this.getValue() + "\n" ); let newPrefix = prefix + "| "; result.append( this.getLeft().internalPrettyPrint( newPrefix ) ); result.append( this.getRight().internalPrettyPrint( newPrefix ) ); return result.toString; } | ||||||||||||||||
| > > |
public | ||||||||||||||||
| Changed: | |||||||||||||||||
| < < |
public Tree | ||||||||||||||||
| > > | prettyPrint(t@Interior, prefix) { let result = new StringBuffer?( prefix + t.value() + "\n" ); let newPrefix = prefix + "| "; result.append( t.left().prettyPrint( newPrefix ) ); result.append( t.right().prettyPrint( newPrefix ) ); return result.toString(); | ||||||||||||||||
| Added: | |||||||||||||||||
| > > |
Tree implementationsTreeVisitorClassesIntermediateExample gives implementations for the binary tree and n-ary tree. | ||||||||||||||||
| <<O>> Difference Topic TreeVisitorIntermediateExample (r1.1 - 05 Sep 2003 - IsaacGouy) |
| Added: | |
| > > |
%META:TOPICINFO{author="IsaacGouy" date="1062781980" format="1.0" version="1.1"}%
%META:TOPICPARENT{name="CodeExamples"}%
Tree and Interior represent a simple binary tree; which is extended with a subclass representing n-ary trees and 3 separate external methods ExtendedTreeVisitorIntermediateExample.
// compilation unit Tree.nice
package openclassdispatch;
public class Tree<T> {
private !T value;
// internal implementation of prettyPrinting to
// measure regular dispatch speed
// Unlike MultiJava, in Nice there's no difference
// to methods defined externally - like prettyPrint
public String internalPrettyPrint(String prefix);
internalPrettyPrint(prefix) =
prefix + this.getValue().toString + "\n";
public String internalPrettyPrint();
internalPrettyPrint() = this.internalPrettyPrint("");
public !T getValue() = value;
}
// compilation unit Interior.nice
package openclassdispatch;
public class Interior<T> extends Tree {
private Tree<T> left;
private Tree<T> right;
// internal implementation of prettyPrinting to
// measure regular dispatch speed
// Unlike MultiJava, in Nice there's no difference
// to methods defined externally - like prettyPrint
internalPrettyPrint(prefix) {
let result = new StringBuffer( prefix + this.getValue() + "\n" );
let newPrefix = prefix + "| ";
result.append( this.getLeft().internalPrettyPrint( newPrefix ) );
result.append( this.getRight().internalPrettyPrint( newPrefix ) );
return result.toString;
}
public Tree<T> getLeft() = left;
public Tree<T> getRight() = right;
}
-- IsaacGouy - 05 Sep 2003
%META:TOPICMOVED{by="IsaacGouy" date="1062782272" from="Doc.ExtensibleVisitorIntermediateExample" to="Doc.TreeVisitorIntermediateExample"}% |
| Topic TreeVisitorIntermediateExample . { View | Diffs | r1.3 | > | r1.2 | > | r1.1 | More } |
|
Revision r1.1 - 05 Sep 2003 - 17:13 GMT - IsaacGouy Revision r1.3 - 24 Dec 2003 - 21:34 GMT - IsaacGouy |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |