diff options
author | Leon Bottou <leon@bottou.org> | 2013-04-06 02:50:32 +0400 |
---|---|---|
committer | Leon Bottou <leon@bottou.org> | 2013-08-11 01:37:09 +0400 |
commit | b416e79b8a43147b3e5656f40625a12d194007ef (patch) | |
tree | 1085b2ec7923e712ebf9f514034a48441c916456 /utils.c | |
parent | 962e1df4a7035141ee115e7d2543dc2db0f92fce (diff) |
ported package torch to win
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 27 |
1 files changed, 20 insertions, 7 deletions
@@ -1,7 +1,11 @@ #include "general.h" #include "utils.h" -#include <sys/time.h> +#ifdef WIN32 +# include <time.h> +#else +# include <sys/time.h> +#endif #ifdef _OPENMP #include <omp.h> @@ -68,20 +72,29 @@ static int torch_isatty(lua_State *L) return 1; } +static double real_time() +{ +#ifdef LUA_WIN + time_t ltime; + time(<ime); + return (double)(ltime); +#else + struct timeval current; + gettimeofday(¤t, NULL); + return (current.tv_sec + current.tv_usec/1000000.0); +#endif +} + static int torch_lua_tic(lua_State* L) { - struct timeval tv; - gettimeofday(&tv,NULL); - double ttime = (double)tv.tv_sec + (double)(tv.tv_usec)/1000000.0; + double ttime = real_time(); lua_pushnumber(L,ttime); return 1; } static int torch_lua_toc(lua_State* L) { - struct timeval tv; - gettimeofday(&tv,NULL); - double toctime = (double)tv.tv_sec + (double)(tv.tv_usec)/1000000.0; + double toctime = real_time(); lua_Number tictime = luaL_checknumber(L,1); lua_pushnumber(L,toctime-tictime); return 1; |