编程语言EF速度测试(5):binary-trees

29 篇文章 1 订阅
23 篇文章 0 订阅

这是一个专门的编程语言/编译器速度测试/对比网站(http://shootout.alioth.debian.org/)给出的题目,

以下是EF源代码:

//binary-trees
public class 启动类 <作者 = "liigo">
{
	const int minDepth = 4;

	public static main()
	{
		int time = 运行环境.取启动时间();
		int n = 16;

		int maxDepth =  n;
		if(minDepth + 2 > n) maxDepth = minDepth + 2;

		int stretchDepth = maxDepth + 1;

		int check = (TreeNode.bottomUpTree(0,stretchDepth)).itemCheck();
		控制台.输出行("stretch tree of depth ", stretchDepth, "/t check: ", check);

		TreeNode longLivedTree = TreeNode.bottomUpTree(0,maxDepth);

		for (int depth=minDepth; depth<=maxDepth; depth+=2){
			int iterations = 1 << (maxDepth - depth + minDepth);
			check = 0;

			for (int i=1; i<=iterations; i++){
				check += (TreeNode.bottomUpTree(i,depth)).itemCheck();
				check += (TreeNode.bottomUpTree(-i,depth)).itemCheck();
			}
			控制台.输出行((iterations*2), "/t trees of depth ", depth, "/t check: ", check);
		}
		控制台.输出行("long lived tree of depth ", maxDepth, "/t check: ", longLivedTree.itemCheck());
		控制台.输出行("time(ms): ", 运行环境.取启动时间() - time);
		控制台.输入文本();
	}


	private class TreeNode
	{
		private TreeNode left, right;
		private int item;

		public init(int item){
			this.item = item;
		}

		public static TreeNode bottomUpTree(int item, int depth){
			if (depth>0){
				return new TreeNode(
					bottomUpTree(2*item-1, depth-1)
					, bottomUpTree(2*item, depth-1)
					, item
					);
			}
			else {
				return new TreeNode(item);
			}
		}

		public init(TreeNode left, TreeNode right, int item){
			this.left = left;
			this.right = right;
			this.item = item;
		}

		public int itemCheck(){
			// if necessary deallocate here
			if (left==null) return item;
			else return item + left.itemCheck() - right.itemCheck();
		}
	}
}

这个EF程序,在我的机器上,运行耗时约 108 秒。相应的VC6最佳优化后运行耗时约 6.9 秒。

其它编程语言/编译器的表现,请看这里:http://shootout.alioth.debian.org/gp4/benchmark.php?test=binarytrees&lang=all

针对这次测试,EF表现较差,是开赛以来最差的一次,比大多数语言都要慢,仅比 Ruby, PHP, JavaScript, Perl, TCL, Rebol 快一些。这次测试的两个特点是:递归,和创建大量小对象(约3000万),EF在这两方面似乎表现不佳。

(这次VC6的表现也很不好。)

还有很多测试题目,有时间再继续。想了解EF语言,请到EF官方博客:http://blog.csdn.net/efdev/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值