File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111#include "runtime.h"
1212
1313STATIC mp_obj_t mod_time_time () {
14+ #if MICROPY_ENABLE_FLOAT
15+ struct timeval tv ;
16+ gettimeofday (& tv , NULL );
17+ mp_float_t val = tv .tv_sec + (mp_float_t )tv .tv_usec / 1000000 ;
18+ return mp_obj_new_float (val );
19+ #else
1420 return mp_obj_new_int ((machine_int_t )time (NULL ));
21+ #endif
1522}
1623STATIC MP_DEFINE_CONST_FUN_OBJ_0 (mod_time_time_obj , mod_time_time );
1724
1825// Note: this is deprecated since CPy3.3, but pystone still uses it.
1926STATIC mp_obj_t mod_time_clock () {
20- // return mp_obj_new_int((machine_int_t)clock());
21- // POSIX requires CLOCKS_PER_SEC equals 1000000, so that's what we assume
27+ #if MICROPY_ENABLE_FLOAT
28+ // POSIX requires CLOCKS_PER_SEC equals 1000000, so that's what we assume.
2229 // float cannot represent full range of int32 precisely, so we pre-divide
2330 // int to reduce resolution, and then actually do float division hoping
2431 // to preserve integer part resolution.
2532 return mp_obj_new_float ((float )(clock () / 1000 ) / 1000.0 );
33+ #else
34+ return mp_obj_new_int ((machine_int_t )clock ());
35+ #endif
2636}
2737STATIC MP_DEFINE_CONST_FUN_OBJ_0 (mod_time_clock_obj , mod_time_clock );
2838
You can’t perform that action at this time.
0 commit comments