benchmark.py

Created by cent20

Created on March 23, 2022

819 Bytes

Script de Xavier Andréani (tiplanet.org) pour tester les performances des calculatrices en python.


# https://tiplanet.org/forum/viewtopic.php?f=49&t=25151
# seuil(0.008) et isprimep(10000019)

from time import monotonic

def hastime():
  try:
    monotonic()
    return True
  except:
    return False

def seuil(d):
  timed,n=hastime(),0
  start,u=0 or timed and monotonic(),2.
  d=d**2
  while (u-1)**2>=d:
    u=1+1/((1-u)*(n+1))
    n=n+1
  return [(timed and monotonic() or 1)-start,n,u]

def nodivisorin(n,l):
  for k in l:
    if n//k*k==n:
      return False
  return True

def isprimep(n):
  t=hastime()
  s,l,k=0 or t and monotonic(),[3],7
  if n==2 or n==5:return True
  if int(n)!=n or n//2*2==n or n//5*5==5:
    return False
  if n<k:return n in l
  while k*k<n:
    if nodivisorin(k,l):l.append(k)
    k+=2+2*((k+2)//5*5==k+2)
  r=nodivisorin(n,l)
  return (t and monotonic() or 1)-s,r

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.