1*fe36f081STimo Kreuzer // Copyright (c) Microsoft. All rights reserved. 2*fe36f081STimo Kreuzer // Licensed under the MIT license. See LICENSE file in the project root for 3*fe36f081STimo Kreuzer // full license information. 4*fe36f081STimo Kreuzer 5*fe36f081STimo Kreuzer #include <stdio.h> 6*fe36f081STimo Kreuzer #include <windows.h> 7*fe36f081STimo Kreuzer #ifdef _M_CEE 8*fe36f081STimo Kreuzer #define MAX_REC 200 9*fe36f081STimo Kreuzer #else 10*fe36f081STimo Kreuzer #define MAX_REC 200 11*fe36f081STimo Kreuzer #endif 12*fe36f081STimo Kreuzer 13*fe36f081STimo Kreuzer #define NLOOPS 10 14*fe36f081STimo Kreuzer 15*fe36f081STimo Kreuzer #if defined(_M_SH) || defined(TRISC) 16*fe36f081STimo Kreuzer #undef MAX_REC 17*fe36f081STimo Kreuzer #define MAX_REC 3 18*fe36f081STimo Kreuzer #endif 19*fe36f081STimo Kreuzer 20*fe36f081STimo Kreuzer #if defined(_M_AMD64) 21*fe36f081STimo Kreuzer #undef MAX_REC 22*fe36f081STimo Kreuzer #define MAX_REC 50 23*fe36f081STimo Kreuzer #endif 24*fe36f081STimo Kreuzer foo(int level)25*fe36f081STimo Kreuzervoid foo(int level) 26*fe36f081STimo Kreuzer { 27*fe36f081STimo Kreuzer if(level < MAX_REC) 28*fe36f081STimo Kreuzer { 29*fe36f081STimo Kreuzer try 30*fe36f081STimo Kreuzer { 31*fe36f081STimo Kreuzer foo(level+1); 32*fe36f081STimo Kreuzer } 33*fe36f081STimo Kreuzer catch(int& throw_level) 34*fe36f081STimo Kreuzer { 35*fe36f081STimo Kreuzer //printf("Level %d catched level %d\n",level,throw_level); 36*fe36f081STimo Kreuzer throw_level = level; 37*fe36f081STimo Kreuzer //printf("Level %d throwing\n",level); 38*fe36f081STimo Kreuzer throw level; 39*fe36f081STimo Kreuzer } 40*fe36f081STimo Kreuzer } 41*fe36f081STimo Kreuzer else 42*fe36f081STimo Kreuzer { 43*fe36f081STimo Kreuzer printf("Level MAX_REC throwing.\n"); 44*fe36f081STimo Kreuzer throw level; 45*fe36f081STimo Kreuzer } 46*fe36f081STimo Kreuzer } 47*fe36f081STimo Kreuzer main(void)48*fe36f081STimo Kreuzerint main(void) 49*fe36f081STimo Kreuzer { 50*fe36f081STimo Kreuzer int n; 51*fe36f081STimo Kreuzer LARGE_INTEGER freq,start,end; 52*fe36f081STimo Kreuzer 53*fe36f081STimo Kreuzer #if !defined(_M_AMD64) && !defined(_M_ARM) && !defined(_M_ARM64) 54*fe36f081STimo Kreuzer QueryPerformanceFrequency(&freq); 55*fe36f081STimo Kreuzer QueryPerformanceCounter(&start); 56*fe36f081STimo Kreuzer #endif 57*fe36f081STimo Kreuzer 58*fe36f081STimo Kreuzer //printf("Max Recursion level: %d\n", MAX_REC); 59*fe36f081STimo Kreuzer printf("N loops: %d\n", NLOOPS); 60*fe36f081STimo Kreuzer 61*fe36f081STimo Kreuzer for(n=0;n<NLOOPS;n++) 62*fe36f081STimo Kreuzer { 63*fe36f081STimo Kreuzer try 64*fe36f081STimo Kreuzer { 65*fe36f081STimo Kreuzer foo(0); 66*fe36f081STimo Kreuzer } 67*fe36f081STimo Kreuzer catch(int& throw_level) 68*fe36f081STimo Kreuzer { 69*fe36f081STimo Kreuzer printf("main catched level %d\n",throw_level); 70*fe36f081STimo Kreuzer } 71*fe36f081STimo Kreuzer } 72*fe36f081STimo Kreuzer #if !defined(_M_AMD64) && !defined(_M_ARM) && !defined(_M_ARM64) 73*fe36f081STimo Kreuzer QueryPerformanceCounter(&end); 74*fe36f081STimo Kreuzer #endif 75*fe36f081STimo Kreuzer 76*fe36f081STimo Kreuzer //printf("Exceptions per sec %lf\n",(double)(NLOOPS*MAX_REC)/((double)(end.QuadPart-start.QuadPart)/(double)freq.QuadPart)); 77*fe36f081STimo Kreuzer } 78