@@ -2889,6 +2889,37 @@ uptime_bsd(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
28892889#endif
28902890
28912891
2892+ static PyObject *
2893+ bench_writer (PyObject * self , PyObject * args )
2894+ {
2895+ Py_ssize_t size , loops ;
2896+ if (!PyArg_ParseTuple (args , "nn" , & size , & loops )) {
2897+ return NULL ;
2898+ }
2899+
2900+ PyTime_t t1 , t2 ;
2901+ (void )PyTime_PerfCounterRaw (& t1 );
2902+ for (Py_ssize_t i = 0 ; i < loops ; i ++ ) {
2903+ PyBytesWriter * writer = PyBytesWriter_Create (size );
2904+ if (writer == NULL ) {
2905+ return NULL ;
2906+ }
2907+
2908+ char * str = PyBytesWriter_GetData (writer );
2909+ memset (str , 'x' , size );
2910+
2911+ PyObject * bytes = PyBytesWriter_Finish (writer );
2912+ if (bytes == NULL ) {
2913+ return NULL ;
2914+ }
2915+ Py_DECREF (bytes );
2916+ }
2917+ (void )PyTime_PerfCounterRaw (& t2 );
2918+
2919+ return PyFloat_FromDouble (PyTime_AsSecondsDouble (t2 - t1 ));
2920+ }
2921+
2922+
28922923static PyMethodDef TestMethods [] = {
28932924 {"set_errno" , set_errno , METH_VARARGS },
28942925 {"test_config" , test_config , METH_NOARGS },
@@ -2988,6 +3019,7 @@ static PyMethodDef TestMethods[] = {
29883019#ifdef HAVE_SYSCTLBYNAME
29893020 {"uptime_bsd" , uptime_bsd , METH_NOARGS },
29903021#endif
3022+ {"bench_writer" , bench_writer , METH_VARARGS },
29913023 {NULL , NULL } /* sentinel */
29923024};
29933025
0 commit comments