(phixonline)-->
with javascript_semantics
include mpfr.e
mpz f = mpz_init()
integer n = 2
bool still_running = true,
still_printing = true
constant ten_s = iff(platform()=JS?0.2:10) -- (10s on desktop/Phix, 0.2s under p2js)
while still_running do
atom t0 = time()
mpz_fac_ui(f, n)
still_running = (time()-t0)<ten_s -- (stop once over 10s)
string ct = elapsed(time()-t0), res, what, pt
t0 = time()
if still_printing then
res = shorten(mpz_get_str(f))
what = "printed"
still_printing = (time()-t0)<ten_s -- (stop once over 10s)
else
res = sprintf("%,d digits",mpz_sizeinbase(f,10))
what = "size in base"
end if
pt = elapsed(time()-t0)
printf(1,"factorial(%d):%s, calculated in %s, %s in %s\n",
{n,res,ct,what,pt})
n *= 2
end while