为什么尝试catch块性能与Javascript中的一般块不同

时间:2014-07-23 22:29:28

标签: javascript angularjs

我测试了try catch块并尝试在angularjs中使用catch block less方法。但为什么表现彼此不同。请描述一下。

var format = 'yyyy-MM-dd HH:mm:ss Z'

$scope.time1 = new Date();

$scope.time2 = new Date();

$scope.dif = 0;

$scope.TestMethod = function () {
    var a = 0;

    $scope.time1 = new Date();

    for (var i = 0; i < 1000000000; i++) {

        a +=i;

    }

    $scope.time2 = new Date();
    calculateDif();
}

$scope.TryCatchMethod = function () {
    try {
        var a = 0;

        $scope.time1 = new Date();

        for (var i = 0; i < 1000000000; i++) {

            a +=i;
        }
        $scope.time2 = new Date();
        calculateDif();
    }
    catch (e) {
        throw e;
    }       
}
function calculateDif(){
    $scope.dif = $scope.time2-$scope.time1;
}   

http://plnkr.co/edit/rb1IGuq7x1LIkj1G0R4G?p=preview

0 个答案:

没有答案