[julia-users] Re: jl_stat_ctime

2016-11-01 Thread Jeffrey Sarnoff
If you are working with file information, use e.g. `file_stats=stat(); 
file_creation_time = file_stats.ctime; file_modification_time = 
file_stat.mtime;` 
You will get Float64 values, to make FineComputerTimes from those, 

function FineComputerTime(stat_time::Float64)
   nanosecs = round(UInt64, stat_time * 1.0e9)
   return FineComputerTime(nanosecs)
end




On Tuesday, November 1, 2016 at 3:44:07 PM UTC-4, Jeffrey Sarnoff wrote:
>
> Look at the help for tic() and toc().
> Do you care about interfacing directly with jl_ routines?  If not, and you 
> are trying to make your own harness ... perhaps this would help:
> #=
>Using immutable rather than type with fields that are 
>simple and immediate values keeps information directly
>available (rather than indirectly available, like arrays).
>
>Use Int64 because nanosecond timing uses 64 bits (UInt64).
>
>time_ns() "Get the time in nanoseconds. 
>   The time corresponding to 0 is undefined,
>   and wraps every 5.8 years."
>
>time_zero because the timer is given as a UInt64 value, and 
> there are more of those than positive Int64s.
> =#
>
> const time_zero = [time_ns()]
> get_time_zero() = time_zero[1]
> function set_time_zero(nanoseconds::UInt64)
> time_zero[1] = nanoseconds
> return nanoseconds
> end
>
> immutable FineComputerTime
> seconds::Int64
> nanoseconds::Int64
> end
>
> function FineComputerTime(nanosecs::UInt64)
> nanosecs -= get_time_zero()
> secs, nsecs = fldmod( nanosecs, 1_000_000_000%UInt64 ) # value%UInt64 
> is a fast way to force the type
> return FineComputerTime( Int64(secs), Int64(nsecs) )
> end
>
> FineComputerTime() = FineComputerTime(time_ns())
>
>
>
>
>
>
>
>
> On Friday, October 28, 2016 at 10:07:42 AM UTC-4, Brandon Taylor wrote:
>>
>> Right now in base jl_stat_ctime looks like this:
>>
>> JL_DLLEXPORT double jl_stat_ctime(char *statbuf)
>> {
>> uv_stat_t *s;
>> s = (uv_stat_t*)statbuf;
>> return (double)s->st_ctim.tv_sec + (double)s->st_ctim.tv_nsec * 1e-9;
>> }
>>
>> And it's called with
>>
>> ccall(:jl_stat_ctime,   Float64, (Ptr{UInt8},), buf)
>>
>> I'd like to simplify this.
>>
>> I'd like a type
>>
>> type FineComputerTime
>> seconds::Int
>> nanoseconds::Int
>> end
>>
>> And a way to fill it in using the stat buffer.
>>
>> Can anyone offer some tips? The c code keeps confusing me.
>>
>>
>>
>>
>> I
>>
>

[julia-users] Re: jl_stat_ctime

2016-11-01 Thread Jeffrey Sarnoff
Look at the help for tic() and toc().
Do you care about interfacing directly with jl_ routines?  If not, and you 
are trying to make your own harness ... perhaps this would help:
#=
   Using immutable rather than type with fields that are 
   simple and immediate values keeps information directly
   available (rather than indirectly available, like arrays).

   Use Int64 because nanosecond timing uses 64 bits (UInt64).

   time_ns() "Get the time in nanoseconds. 
  The time corresponding to 0 is undefined,
  and wraps every 5.8 years."

   time_zero because the timer is given as a UInt64 value, and 
there are more of those than positive Int64s.
=#

const time_zero = [time_ns()]
get_time_zero() = time_zero[1]
function set_time_zero(nanoseconds::UInt64)
time_zero[1] = nanoseconds
return nanoseconds
end

immutable FineComputerTime
seconds::Int64
nanoseconds::Int64
end

function FineComputerTime(nanosecs::UInt64)
nanosecs -= get_time_zero()
secs, nsecs = fldmod( nanosecs, 1_000_000_000%UInt64 ) # value%UInt64 
is a fast way to force the type
return FineComputerTime( Int64(secs), Int64(nsecs) )
end

FineComputerTime() = FineComputerTime(time_ns())








On Friday, October 28, 2016 at 10:07:42 AM UTC-4, Brandon Taylor wrote:
>
> Right now in base jl_stat_ctime looks like this:
>
> JL_DLLEXPORT double jl_stat_ctime(char *statbuf)
> {
> uv_stat_t *s;
> s = (uv_stat_t*)statbuf;
> return (double)s->st_ctim.tv_sec + (double)s->st_ctim.tv_nsec * 1e-9;
> }
>
> And it's called with
>
> ccall(:jl_stat_ctime,   Float64, (Ptr{UInt8},), buf)
>
> I'd like to simplify this.
>
> I'd like a type
>
> type FineComputerTime
> seconds::Int
> nanoseconds::Int
> end
>
> And a way to fill it in using the stat buffer.
>
> Can anyone offer some tips? The c code keeps confusing me.
>
>
>
>
> I
>