freenode/lisp - IRC Chatlog
Search
13:51:21
jdz
Bike: Just look at the list of people in this channel, and how many of them you know have typed anything?
13:59:26
flip214
Bike: if there are no members, just assert yourself as the first one -- and declare independence!
14:00:51
phoe
flip214: I don't know if the platinum sponsors club can survive an infinite increase in its member ratio
15:42:19
_Ark_
Does anyone know a way to get a nanosecond/cpu timestamp in Common Lisp (or at least sbcl)? I'm looking for something like Java's `nanoTime` https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#nanoTime()
15:42:25
_Ark_
I've tried `(get-internal-run-time)` along with `internal-time-units-per-second`, but on SBCL it gives milliseconds.
15:44:47
Xach
_Ark_: i don't know if there's a more direct way, but you could use sb-alien to use the underlying OS apis. if you know what OS api provides it, you could also grep SBCL sources for something that uses that API.
15:46:24
pjb
or (com.informatimago.common-lisp.cesarum.time:get-real-time) #| --> 3.794139978273096D+9 |#
15:46:39
pjb
or (com.informatimago.common-lisp.cesarum.time:get-run-time) #| --> 7.1337779999999995D0 |#
15:48:56
_Ark_
Xach: I want to add some built-in profiling to my game engine. Mircoseconds will work for this, but I was curious how fine-grain of time lisp can get.
15:51:00
_Ark_
Yeah I figured FFI was always an option. Was wondering if there was a "standard" way to do this. For some applications nano-time is desierable
15:51:39
Shinmera
That resolution won't be useful because it'll be highly dominated by noise anyway.
15:53:58
_Ark_
I used to be an APM (Application Performance Monitoring) devleoper for the JVM. Basically a simple profiler designed to run in production. We always measured in cpu nanoseconds. In practice it ended up being useful.
15:56:08
_Ark_
Looking though some of the libraries people linked. Seems like `local-time` on sbcl is using `sb-ext:get-time-of-day` under the hood. I'll take a look at monotonic-clock next...
15:58:58
jcowan
U.S. Steel is the corporate descendant of Carnegie Steel. CMU's money didn't come from nowhere.
16:09:25
Bike
steel bank common lisp is descended from carnegie mellon university common lisp, because carnegie was a steel mogul and mellon a banker
16:11:59
_Ark_
For anyone following along, `monotonic-clock` is implemented using FFI. Here's the underlying system call: https://linux.die.net/man/3/clock_gettime
16:12:27
_Ark_
I guess my take-away is that getting the CPU time will required an FFI call (or more desirably using a library that manages the FFI for you). To Shinmera's point, this is overkill and not helpful for most applications, so micro-time is likely what you want.
16:38:22
dlowe
worse, some computers claim to know nanoseconds and then only update their nanosecond counter every microsecond or so
16:44:25
jmercouris
when I use cffi:callback to pass a callback to some C code, how can I store that in the C code? what is it a void *?
16:45:36
pjb
jmercouris: in any case, the cffi declaration of the C function, and the C function itself don't need to have the same type of parameters.
16:45:42
jackdaniel
pjb: in C standard casting function pointers to data pointers is undefined behavior
16:48:37
_death
so, struct { void (*fp)(void); } stuff; void store(void (*fp)(void)) { stuff.fp = fp; }
16:49:07
jackdaniel
jmercouris: please read this piece https://www.cprogramming.com/tutorial/function-pointers.html, I think that discussing C pointers is not very ontopic
16:49:28
Bike
function pointers and data pointers aren't interchangeable but you can use function pointers fine. declare a global variable with function pointer type, put it in a struct, whatever
16:50:01
_death
you'd also want to take a context pointer, i.e. some void pointer to store as well and pass along when calling the function pointer
16:50:08
pjb
jackdaniel: I see only a prevention of casting (void*) to float, in 6.5.4 of ISO/IEC 9899:201x Committee Draft — April 12, 2011 N1570
16:53:29
TMA
pjb: you need to consider the whole standard; undefined behavior need not be explicitely specified, the necessary condition is that the standard does not explicitely or implicitely specify it
16:54:17
pjb
TMA: yes, but then the C standard doesn't specify a Turing Complete language either. So we could stop there.
16:54:46
pjb
TMA: but if it's not formally forbidden, and all C compilers do the right thing, where's the objection?
16:55:30
TMA
pjb: embedded platforms can have function pointers bigger or smaller than data pointers
16:56:54
jackdaniel
pjb: in 6.3.2.3 (same document), pointes 7. and 8.; there is no specification about casting between object and function pointers
17:00:12
jackdaniel
it is certainly nice that it "usually works", but I think that there are architectures where normal data pointer is insufficient to store function address
17:00:26
pjb
Ok, so it could work or not, it's implementation dependent. So we'd need to cast to something like int(*)() or void(*)() perhaps. typedef void(*function_ptr)();
17:02:27
pjb
Anyways, my point was that the CFFI declaration of _death's store function above doesn't need to use the type of void(*fp)(void) as argument, but can take the cffi:callback type.
17:03:22
pjb
Said otherwise, FFIs don't validate the function signatures across languages. If it could, we wouldn't have to declare the C functions in lisp!
17:13:47
jmercouris
not to fuel the off-topic discussion, but I read somewhere that it is apparently a posix specification that it should work
17:56:15
flip214
_Ark_: SBCL shows the CPU cycles in (time), (sb-ext:call-with-timing) can give that without parsing text, and then there's (sb-impl::read-cycle-counter) ...
18:30:16
jackdaniel
that is correct, dlsym returns a void pointer, it is briefly discussed here https://en.wikipedia.org/wiki/Dynamic_loading