/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* return pointer to formatted clock() tics t24* return value length is at most 625*/2627#include <ast.h>28#include <tm.h>2930char*31fmtclock(register Sfulong_t t)32{33register int u;34char* buf;35int z;3637static unsigned int clk_tck;3839if (!clk_tck)40{41#ifdef CLOCKS_PER_SEC42clk_tck = CLOCKS_PER_SEC;43#else44if (!(clk_tck = (unsigned int)strtoul(astconf("CLK_TCK", NiL, NiL), NiL, 10)))45clk_tck = 60;46#endif47}48if (t == 0)49return "0";50if (t == ((Sfulong_t)~0))51return "%";52t = (t * 1000000) / clk_tck;53if (t < 1000)54u = 'u';55else if ((t /= 1000) < 1000)56u = 'm';57else58return fmtelapsed(t / 10, 100);59buf = fmtbuf(z = 7);60sfsprintf(buf, z, "%I*u%cs", sizeof(t), t, u);61return buf;62}636465