Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Python's time.clock calls C function clock(3) -- <code>man clock</code> should confirm that it's supposed to work on BSD, so I don't know why it's not working for you. Maybe you can try working around this apparent bug in your Python port by using <code>ctypes</code> to call the clock function from the system C library directly (if you have said library as a .so/.dynlib/.dll or whatever dynamic shared libraries are called on FreeBSD)?</p> <p>time.time is supposed to be very high resolution, BTW, as internally it calls gettimeofday (well, in a properly built Python, anyway) -- what resolution do you observe for it on your system?</p> <p><strong>Edit</strong>: here's <code>wat.c</code>, a BSD-specific extension (tested on my Mac only -- sorry but I have no other BSD flavor at hand right know) to work around this apparent FreeBSD port problem:</p> <pre><code>#include "Python.h" #include &lt;sys/time.h&gt; static PyObject * wat_time(PyObject *self, PyObject *args) { struct timeval t; if (gettimeofday(&amp;t, (struct timezone *)NULL) == 0) { double result = (double)t.tv_sec + t.tv_usec*0.000001; return PyFloat_FromDouble(result); } return PyErr_SetFromErrno(PyExc_OSError); } static PyMethodDef wat_methods[] = { {"time", wat_time, METH_VARARGS, PyDoc_STR("time() -&gt; microseconds since epoch")}, {NULL, NULL} /* sentinel */ }; PyDoc_STRVAR(wat_module_doc, "Workaround for time.time issues on FreeBsd."); PyMODINIT_FUNC initwat(void) { Py_InitModule3("wat", wat_methods, wat_module_doc); } </code></pre> <p>And here's the <code>setup.py</code> to put in the same directory:</p> <pre><code>from distutils.core import setup, Extension setup (name = "wat", version = "0.1", maintainer = "Alex Martelli", maintainer_email = "aleaxit@gmail.com", url = "http://www.aleax.it/wat.zip", description = "WorkAround for Time in FreeBSD", ext_modules = [Extension('wat', sources=['wat.c'])], ) </code></pre> <p>The URL is correct, so you can also get these two files zipped up <a href="http://ttp://www.aleax.it/wat.zip" rel="nofollow noreferrer">here</a>.</p> <p>To build &amp; install this extension, <code>python setup.py install</code> (if you have permission to write in your Python's installation) or <code>python setup.py build_ext -i</code> to write wat.so in the very directory in which you put the sources (and then manually move it wherever you prefer to have it, but first try it out e.g. with <code>python -c'import wat; print repr(wat.time())'</code> in the same directory in which you've built it).</p> <p>Please let me know how it works on FreeBSD (or any other Unix flavor with <code>gettimeofday</code>!-) -- if the C compiler complains about <code>gettimeofday</code>, you may be on a system which doesn't want to see its second argument, try without it!-).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload