Home | History | Annotate | Download | only in libmicro
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms
      5  * of the Common Development and Distribution License
      6  * (the "License").  You may not use this file except
      7  * in compliance with the License.
      8  *
      9  * You can obtain a copy of the license at
     10  * src/OPENSOLARIS.LICENSE
     11  * or http://www.opensolaris.org/os/licensing.
     12  * See the License for the specific language governing
     13  * permissions and limitations under the License.
     14  *
     15  * When distributing Covered Code, include this CDDL
     16  * HEADER in each file and include the License file at
     17  * usr/src/OPENSOLARIS.LICENSE.  If applicable,
     18  * add the following below this CDDL HEADER, with the
     19  * fields enclosed by brackets "[]" replaced with your
     20  * own identifying information: Portions Copyright [yyyy]
     21  * [name of copyright owner]
     22  *
     23  * CDDL HEADER END
     24  */
     25 
     26 /*
     27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
     28  * Use is subject to license terms.
     29  */
     30 
     31 
     32 #include <unistd.h>
     33 #include <stdio.h>
     34 #include <stdlib.h>
     35 #include <string.h>
     36 
     37 #include "libmicro.h"
     38 
     39 #define	DEFD		100
     40 
     41 static int			optd = DEFD;
     42 
     43 int recurse2(int x, int y, char *s);
     44 
     45 /*ARGSUSED*/
     46 int
     47 recurse1(int x, int y, char *s)
     48 {
     49 	char			str[32];
     50 
     51 	if (x < y) {
     52 		return (recurse2(x + 1, y, str));
     53 	}
     54 
     55 	return (x);
     56 }
     57 
     58 int
     59 benchmark_init()
     60 {
     61 	lm_tsdsize = 0;
     62 
     63 	(void) sprintf(lm_optstr, "d:");
     64 
     65 	(void) sprintf(lm_usage,
     66 	    "       [-d depth-limit (default = %d)]\n"
     67 	    "notes: measures recursion performance\n",
     68 	    DEFD);
     69 
     70 	return (0);
     71 }
     72 
     73 int
     74 benchmark_optswitch(int opt, char *optarg)
     75 {
     76 	switch (opt) {
     77 	case 'd':
     78 		optd = atoi(optarg);
     79 		break;
     80 	default:
     81 		return (-1);
     82 	}
     83 	return (0);
     84 }
     85 
     86 /*ARGSUSED*/
     87 int
     88 benchmark(void *tsd, result_t *res)
     89 {
     90 	int			i;
     91 
     92 	for (i = 0; i < lm_optB; i++) {
     93 		(void) recurse1(0, optd, NULL);
     94 	}
     95 	res->re_count = i;
     96 
     97 	return (0);
     98 }
     99