本文整理汇总了C++中difftime函数的典型用法代码示例。如果您正苦于以下问题:C++ difftime函数的具体用法?C++ difftime怎么用?C++ difftime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了difftime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mexFunction
extern void mexFunction(int iNbOut, mxArray *pmxOut[],
int iNbIn, const mxArray *pmxIn[])
{
/* vars in */
float *alpha, *Ct, *pars;
int Nx, Ny, Nz, nLab, maxIt;
float errBound, cc, steps;
/* vars out */
float *u, *cvg;
int *itNum;
double *runTime;
int dim[4];
int nDim;
/* others */
time_t start_time, end_time;
/* compute Max-Flow */
start_time = clock();
/* Inputs */
Ct = mxGetData(pmxIn[0]); /* bound of sink flows */
alpha = mxGetData(pmxIn[1]); /* penalty parameters */
pars = mxGetData(pmxIn[2]); /* Vector of parameters */
/*
*pfVecParameters Setting
* [0] : number of columns
* [1] : number of rows
* [2] : number of slices
* [3] : number of labels
* [4] : the maximum iteration number
* [5] : error criterion
* [6] : cc for the step-size of ALM
* [7] : steps for the step-size of projected-gradient of p
*/
/* pars */
Ny = (int) pars[0];
Nx = (int) pars[1];
Nz = (int) pars[2];
nLab = (int) pars[3];
maxIt = (int) pars[4];
errBound = (float) pars[5];
cc = (float) pars[6];
steps = (float) pars[7];
/* Outputs */
/* outputs the computed u(x) */
dim[0] = Ny;
dim[1] = Nx;
dim[2] = Nz;
dim[3] = nLab;
nDim = 4;
pmxOut[0] = mxCreateNumericArray(nDim,(const int*)dim,mxSINGLE_CLASS,mxREAL);
u = mxGetData(pmxOut[0]);
/* outputs the convergence rate */
nDim = 2;
dim[0] = maxIt;
dim[1] = 1;
pmxOut[1] = mxCreateNumericArray(nDim,(const int*)dim,mxSINGLE_CLASS,mxREAL);
cvg = mxGetData(pmxOut[1]);
/* outputs the iteration number */
nDim = 2;
dim[0] = 1;
dim[1] = 1;
pmxOut[2] = mxCreateNumericArray(nDim,(const int*)dim,mxUINT16_CLASS,mxREAL);
itNum = mxGetData(pmxOut[2]);
/* outputs the computation time */
nDim = 2;
dim[0] = 1;
dim[1] = 1;
pmxOut[3] = mxCreateNumericArray(nDim,(const int*)dim,mxSINGLE_CLASS,mxREAL);
runTime = mxGetData(pmxOut[3]);
/* compute Max-Flow */
start_time = clock();
runMaxFlow(alpha, Ct,
Nx, Ny, Nz, nLab, maxIt, errBound, cc, steps,
u, cvg, itNum);
end_time = clock();
runTime[0] = difftime(end_time, start_time)/1000000;
mexPrintf("potts model max flow 3D: number of iterations = %i; time = %.4f sec\n",itNum[0],runTime[0]);
}
示例2: timertime
flt timertime(void) {
flt a;
a = difftime(stoptime, starttime);
return a;
}
示例3: main
//.........这里部分代码省略.........
else{
*(uint32_t *)snddoutcount_addr = 15;
count = 0;
i = 1;
st = 3;
}
}
else if(st == 3){
if (count < length_max){
*(uint32_t *)hash0_addr = length_alphabet[count];
*(uint32_t *)snddoutcount_addr = i;
if(i == *(uint32_t *)snddincount_addr){
printf("Length information for part %i is sent. %i. \r\n", count, length_alphabet[count]);
count = count + 1;
if(i < 14){ i = i + 1;}
else {i = 1;}
}
}
else {
*(uint32_t *)snddoutcount_addr = 0;
*(uint32_t *)hash0_addr = length_min;
if (0 == *(uint32_t *)snddincount_addr){
*(uint32_t *)snddoutcount_addr = 15;
st = 4;
count = 0;
time (&start);
printf("Done gathering information, starting. \r\n");
}
}
}
else if(st == 4){
*(uint32_t *)snddoutcount_addr = count;
if(count == *(uint32_t *)snddincount_addr){
output[count] = *(uint32_t *)result_addr;
printf("Received part %i\r\n", count);
count = count + 1;
}
if(count >= 16){
st = 5;
count = 0;
time (&end);
dif = difftime (end,start);
printf("%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", output[15], output[14], output[13], output[12], output[11], output[10], output[9], output[8], output[7], output[6], output[5], output[4], output[3], output[2], output[1], output[0]);
}
}
else if (st == 5){
*(uint32_t *)snddoutcount_addr = count;
if(count == *(uint32_t *)snddincount_addr){
rounds[count] = *(uint32_t *)result_addr;
count = count + 1;
}
if (count == 2){
rounds64 = (uint64_t) rounds[1] << 32 | rounds[0];
printf("Number of 20 ns rounds used to find the correct hash: %g\r\n", (double)rounds64);
printf("That equals to %g seconds \r\n", (double)rounds64*0.00000002);
printf("This program measured %g seconds from confirmed hash to received result. \r\n", dif);
st = 0;
}
}
else {
printf("From the left, enter the first 8 digits of the hash: \r\n");
scanf("%x", &hash[4]);
*(uint32_t *)hash0_addr = hash[4];
*(uint32_t *)snddoutcount_addr = 4;
printf("Enter next 8 digits of the hash: \r\n");
scanf("%x", &hash[3]);
*(uint32_t *)hash0_addr = hash[3];
*(uint32_t *)snddoutcount_addr = 3;
printf("Enter next 8 digits of the hash: \r\n");
scanf("%x", &hash[2]);
*(uint32_t *)hash0_addr = hash[2];
*(uint32_t *)snddoutcount_addr = 2;
printf("Enter next 8 digits of the hash: \r\n");
scanf("%x", &hash[1]);
*(uint32_t *)hash0_addr = hash[1];
*(uint32_t *)snddoutcount_addr = 1;
printf("Enter last 8 digits of the hash: \r\n");
scanf("%x", &hash[0]);
*(uint32_t *)hash0_addr = hash[0];
*(uint32_t *)snddoutcount_addr = 0;
printf("%x %x %x %x %x\n", hash[4], hash[3], hash[2], hash[1], hash[0]);
st = 1;
count = 0;
*(uint32_t *)snddoutcount_addr = 10;
corr = 0;
}
}
return 0;
}
示例4: main
//.........这里部分代码省略.........
int h=state.height;
dstImage = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3);
py = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1); // Y component of YUV I420 frame
pu = cvCreateImage(cvSize(w/2,h/2), IPL_DEPTH_8U, 1); // U component of YUV I420 frame
pv = cvCreateImage(cvSize(w/2,h/2), IPL_DEPTH_8U, 1); // V component of YUV I420 frame
pu_big = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1);
pv_big = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1);
image = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3); // final picture to display
// create camera
if (!create_camera_component(&state))
{
vcos_log_error("%s: Failed to create camera component", __func__);
}
// AZG(20160226): Debug
else if ((status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS)
{
vcos_log_error("%s: Failed to create preview component", __func__);
destroy_camera_component(&state);
}
else
{
PORT_USERDATA callback_data;
camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT];
camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT];
VCOS_STATUS_T vcos_status;
callback_data.pstate = &state;
vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "RaspiStill-sem", 0);
vcos_assert(vcos_status == VCOS_SUCCESS);
// assign data to use for callback
camera_video_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data;
// init timer
time(&timer_begin);
// start capture
if (mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS)
{
goto error;
}
// Send all the buffers to the video port
int num = mmal_queue_length(state.video_pool->queue);
int q;
for (q=0; q<num; q++)
{
MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.video_pool->queue);
if (!buffer)
vcos_log_error("Unable to get a required buffer %d from pool queue", q);
if (mmal_port_send_buffer(camera_video_port, buffer)!= MMAL_SUCCESS)
vcos_log_error("Unable to send a buffer to encoder output port (%d)", q);
}
// Now wait until we need to stop
vcos_sleep(state.timeout);
error:
mmal_status_to_int(status);
// Disable all our ports that are not handled by connections
check_disable_port(camera_still_port);
if (state.camera_component)
mmal_component_disable(state.camera_component);
//destroy_encoder_component(&state);
// raspipreview_destroy(&state.preview_parameters);
destroy_camera_component(&state);
}
if (status != 0)
raspicamcontrol_check_configuration(128);
time(&timer_end); /* get current time; same as: timer = time(NULL) */
cvReleaseImage(&dstImage);
cvReleaseImage(&pu);
cvReleaseImage(&pv);
cvReleaseImage(&py);
cvReleaseImage(&pu_big);
cvReleaseImage(&pv_big);
secondsElapsed = difftime(timer_end,timer_begin);
printf ("%.f seconds for %d frames : FPS = %f\n", secondsElapsed,nCount,(float)((float)(nCount)/secondsElapsed));
return 0;
}
示例5: php_setcookie
PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, time_t expires, char *path, int path_len, char *domain, int domain_len, int secure, int url_encode, int httponly TSRMLS_DC)
{
char *cookie;
int len=sizeof("Set-Cookie: ");
zend_string *dt;
sapi_header_line ctr = {0};
int result;
zend_string *encoded_value = NULL;
if (name && strpbrk(name, "=,; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */
zend_error( E_WARNING, "Cookie names cannot contain any of the following '=,; \\t\\r\\n\\013\\014'" );
return FAILURE;
}
if (!url_encode && value && strpbrk(value, ",; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */
zend_error( E_WARNING, "Cookie values cannot contain any of the following ',; \\t\\r\\n\\013\\014'" );
return FAILURE;
}
len += name_len;
if (value && url_encode) {
encoded_value = php_url_encode(value, value_len);
len += encoded_value->len;
} else if (value) {
encoded_value = zend_string_init(value, value_len, 0);
len += encoded_value->len;
}
if (path) {
len += path_len;
}
if (domain) {
len += domain_len;
}
cookie = emalloc(len + 100);
if (value && value_len == 0) {
/*
* MSIE doesn't delete a cookie when you set it to a null value
* so in order to force cookies to be deleted, even on MSIE, we
* pick an expiry date in the past
*/
dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, 1, 0 TSRMLS_CC);
snprintf(cookie, len + 100, "Set-Cookie: %s=deleted; expires=%s; Max-Age=0", name, dt->val);
zend_string_free(dt);
} else {
snprintf(cookie, len + 100, "Set-Cookie: %s=%s", name, value ? encoded_value->val : "");
if (expires > 0) {
const char *p;
char tsdelta[13];
strlcat(cookie, COOKIE_EXPIRES, len + 100);
dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, expires, 0 TSRMLS_CC);
/* check to make sure that the year does not exceed 4 digits in length */
p = zend_memrchr(dt->val, '-', dt->len);
if (!p || *(p + 5) != ' ') {
zend_string_free(dt);
efree(cookie);
zend_string_free(encoded_value);
zend_error(E_WARNING, "Expiry date cannot have a year greater than 9999");
return FAILURE;
}
strlcat(cookie, dt->val, len + 100);
zend_string_free(dt);
snprintf(tsdelta, sizeof(tsdelta), ZEND_LONG_FMT, (zend_long) difftime(expires, time(NULL)));
strlcat(cookie, COOKIE_MAX_AGE, len + 100);
strlcat(cookie, tsdelta, len + 100);
}
}
if (encoded_value) {
zend_string_free(encoded_value);
}
if (path && path_len > 0) {
strlcat(cookie, COOKIE_PATH, len + 100);
strlcat(cookie, path, len + 100);
}
if (domain && domain_len > 0) {
strlcat(cookie, COOKIE_DOMAIN, len + 100);
strlcat(cookie, domain, len + 100);
}
if (secure) {
strlcat(cookie, COOKIE_SECURE, len + 100);
}
if (httponly) {
strlcat(cookie, COOKIE_HTTPONLY, len + 100);
}
ctr.line = cookie;
ctr.line_len = strlen(cookie);
result = sapi_header_op(SAPI_HEADER_ADD, &ctr TSRMLS_CC);
efree(cookie);
return result;
}
示例6: main
int main(int argc, char **argv){
if(argc==1){ fprintf(stderr, "Error- Usage: %s <Port #>\n",argv[0]); return -1;}
int s,s2,port;
struct sockaddr_in sin, from;
int len = sizeof from;
sin.sin_family = AF_INET;
if((port=atoi(argv[1]))<1025){
fprintf(stderr, "Error- Invalid Port #: %s\n", argv[1]);
return -1;
}
sin.sin_port = htons(port);
sin.sin_addr.s_addr=INADDR_ANY;
if((s=socket(AF_INET, SOCK_STREAM,0))==-1){perror("Error creating socket."); return -1;}
if(bind(s, (struct sockaddr *)&sin, sizeof sin)<0){
perror("Error binding socket to sockaddr.");
close(s);
return -1;
}
if(listen(s,128)<0){ perror("Error Listening for TCP Connections."); close(s); return -1; }
if((s2=accept(s, (struct sockaddr *)&from,&len))<0){
perror("Error Accepting TCP Connection"); close(s); return -1;
}
int r,r_full,n;
int bsize = 4096;
int bytes = 0;
char *buf = malloc(bsize);
if(buf==NULL){perror("Error Allocating Memory for buffer"); close(s); return -1;}
char *buf_tmp;
struct timeval begin,end;
if(gettimeofday(&begin,NULL)==-1){ perror("Error recording begin-time of read from socket"); close(s); return -1; }
while((r = read(s2,buf,bsize))!=0){
if(r==-1){ perror("Error reading from socket"); close(s); return -1; }
buf_tmp = buf; r_full = r;
while((n=write(1,buf_tmp,r))!=r && n!=-1){
buf_tmp = buf_tmp+n;
r-=n;
}
if(n==-1){ perror("Error writing to output"); close(s); return -1; }
bytes+=r_full;
}
close(s);close(s2);
if(gettimeofday(&end,NULL)==-1){ perror("Error recording end-time of read from socket"); close(s); return -1; }
double secs = difftime(end.tv_sec,begin.tv_sec);
double usecs = difftime(end.tv_usec,begin.tv_usec)/1000000;
secs += usecs;
double rate = bytes/secs/1048576;
struct hostent *he;
if(!(he=gethostbyaddr((char *)&from.sin_addr, sizeof from.sin_addr, AF_INET))){
fprintf(stderr, "Error retrieving information on TCP sender\n");
herror(" ");
close(s);
return -1;
}
char *ip = inet_ntoa(from.sin_addr);
fprintf(stderr, "Remote Endpoint:\n\tIP address: %s\n",ip);
if(he->h_name) fprintf(stderr, "\tName: %s\n", he->h_name);
fprintf(stderr, "\tPort: %d\n", ntohs(from.sin_port));
fprintf(stderr, "Bytes Sent:\t%d\nTransfer Rate:\t%f MB/s\n",bytes,rate);
close(s); free(buf);
return 0;
}
示例7: np_net_ssl_check_cert
int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
# ifdef USE_OPENSSL
X509 *certificate=NULL;
X509_NAME *subj=NULL;
char timestamp[50] = "";
char cn[MAX_CN_LENGTH]= "";
char *tz;
int cnlen =-1;
int status=STATE_UNKNOWN;
ASN1_STRING *tm;
int offset;
struct tm stamp;
float time_left;
int days_left;
int time_remaining;
time_t tm_t;
certificate=SSL_get_peer_certificate(s);
if (!certificate) {
printf("%s\n",_("CRITICAL - Cannot retrieve server certificate."));
return STATE_CRITICAL;
}
/* Extract CN from certificate subject */
subj=X509_get_subject_name(certificate);
if (!subj) {
printf("%s\n",_("CRITICAL - Cannot retrieve certificate subject."));
return STATE_CRITICAL;
}
cnlen = X509_NAME_get_text_by_NID(subj, NID_commonName, cn, sizeof(cn));
if (cnlen == -1)
strcpy(cn, _("Unknown CN"));
/* Retrieve timestamp of certificate */
tm = X509_get_notAfter(certificate);
/* Generate tm structure to process timestamp */
if (tm->type == V_ASN1_UTCTIME) {
if (tm->length < 10) {
printf("%s\n", _("CRITICAL - Wrong time format in certificate."));
return STATE_CRITICAL;
} else {
stamp.tm_year = (tm->data[0] - '0') * 10 + (tm->data[1] - '0');
if (stamp.tm_year < 50)
stamp.tm_year += 100;
offset = 0;
}
} else {
if (tm->length < 12) {
printf("%s\n", _("CRITICAL - Wrong time format in certificate."));
return STATE_CRITICAL;
} else {
stamp.tm_year =
(tm->data[0] - '0') * 1000 + (tm->data[1] - '0') * 100 +
(tm->data[2] - '0') * 10 + (tm->data[3] - '0');
stamp.tm_year -= 1900;
offset = 2;
}
}
stamp.tm_mon =
(tm->data[2 + offset] - '0') * 10 + (tm->data[3 + offset] - '0') - 1;
stamp.tm_mday =
(tm->data[4 + offset] - '0') * 10 + (tm->data[5 + offset] - '0');
stamp.tm_hour =
(tm->data[6 + offset] - '0') * 10 + (tm->data[7 + offset] - '0');
stamp.tm_min =
(tm->data[8 + offset] - '0') * 10 + (tm->data[9 + offset] - '0');
stamp.tm_sec =
(tm->data[10 + offset] - '0') * 10 + (tm->data[11 + offset] - '0');
stamp.tm_isdst = -1;
tm_t = timegm(&stamp);
time_left = difftime(tm_t, time(NULL));
days_left = time_left / 86400;
tz = getenv("TZ");
setenv("TZ", "GMT", 1);
tzset();
strftime(timestamp, 50, "%c %z", localtime(&tm_t));
if (tz)
setenv("TZ", tz, 1);
else
unsetenv("TZ");
tzset();
if (days_left > 0 && days_left <= days_till_exp_warn) {
printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp);
if (days_left > days_till_exp_crit)
status = STATE_WARNING;
else
status = STATE_CRITICAL;
} else if (days_left == 0 && time_left > 0) {
if (time_left >= 3600)
time_remaining = (int) time_left / 3600;
else
time_remaining = (int) time_left / 60;
printf (_("%s - Certificate '%s' expires in %u %s (%s)\n"),
//.........这里部分代码省略.........
示例8: show_whitelist_ip
int show_whitelist_ip(void)
{
cmd_hdr *cmd;
get_wl_ip_key_obj *req;
get_wl_ip_key_obj next;
get_wl_ip_acl_obj *wl_obj;
src_dest_acl_obj *acl_obj;
time_t cur_time;
double delta_time;
char buf[1024];
char *pbuf = buf;
char src_ip[15];
char dst_ip[15];
char acl_id[15];
int secs_left;
int i;
int ctr = 1;
int buf_len;
int more = TRUE;
int is_first = TRUE;
int ret;
memset(&next, 0, sizeof(next));
while (more)
{
cmd = (cmd_hdr *)pbuf;
memset(cmd, 0, sizeof(cmd_hdr));
cmd->type = CMD_REQUEST;
cmd->cmd_id = CMD_GET_WHITELIST_IP;
cmd++;
req = (get_wl_ip_key_obj *)cmd;
*req = next;
req++;
buf_len = sizeof(buf);
ret = send_req((char *)pbuf, ((char *)req - buf), (char *)buf, &buf_len);
if (ret)
{
fprintf(stdout, "Daemon is down.\n");
break;
}
cmd = (cmd_hdr *)buf;
if ((cmd->type != CMD_RESPONSE) || (cmd->cmd_id != CMD_GET_WHITELIST_IP))
{
fprintf(stdout, " Unexpected response. Skipping.\n");
break;
}
cmd++;
wl_obj = (get_wl_ip_acl_obj *)cmd;
if (is_first)
{
fprintf(stdout, "Whitelisted Source-Destination IP Pair\n");
fprintf(stdout, "======================================\n");
fprintf(stdout, "ID SourceIP DestinationIP Seconds Left Age\n\n");
if (!wl_obj->n_acl)
{
fprintf(stdout, " No whitelisted source-destination IPs.\n");
break;
}
is_first = FALSE;
}
if (!wl_obj->n_acl)
{
break;
}
cur_time = time(NULL);
acl_obj = (src_dest_acl_obj *)(wl_obj + 1);
for (i = 0; i < wl_obj->n_acl; i++, acl_obj++, ctr++)
{
snprintf(src_ip, sizeof(src_ip), "%d.%d.%d.%d",
(acl_obj->src >> 24) & 0xFF,
(acl_obj->src >> 16) & 0xFF,
(acl_obj->src >> 8) & 0xFF,
acl_obj->src & 0xFF);
snprintf(dst_ip, sizeof(dst_ip), "%d.%d.%d.%d",
(acl_obj->dst >> 24) & 0xFF,
(acl_obj->dst >> 16) & 0xFF,
(acl_obj->dst >> 8) & 0xFF,
acl_obj->dst & 0xFF);
snprintf(acl_id, sizeof(acl_id), "[%d]", ctr);
delta_time = difftime(cur_time, (time_t)acl_obj->created_at);
secs_left = acl_obj->age - (int)delta_time;
fprintf(stdout, "%-5s %-16s %-16s %-5d %lu\n",
acl_id, src_ip, dst_ip, secs_left, acl_obj->age);
//.........这里部分代码省略.........
示例9: time
void TrackProgress::ReportState(char *my_state){
time(&analysis_current_time);
fprintf(stdout, "\n%s: Elapsed: %.1lf minutes\n\n", my_state, difftime(analysis_current_time, analysis_start_time) / 60);
fprintf(fpLog, "%s = %.1lf minutes\n", my_state, difftime(analysis_current_time, analysis_start_time) / 60);
fflush(NULL);
}
示例10: seconds_since_last_use
double seconds_since_last_use(void)
{
return difftime(time(NULL), iqlast);
}
示例11: main
//int main (int argc, char * const argv[]) {
int main() {
time_t startTime = time(0);
time_t currentTime;
unsigned long long sec;
time_t treePairAverage = 0;
#ifndef MACOSX
locale::global(locale("en_US.UTF-8"));
#endif //#ifdef MACOSX
/* chudInitialize();
chudMarkPID(getpid(),1);
chudAcquireRemoteAccess();
chudStartRemotePerfMonitor("testthetester");*/
Tree::binariseMode = false;
wifstream input;
wcout << "DATA_SET: " << DATA_SET << endl;
//HomeCenter data
if (DATA_SET == "HomeCentre") {
NonTerminal::idBase.reset(500);
Tree::pairedMode = true;
input.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/HomeCentre/new_manual.txt");
// input.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/HomeCentre/en-fr HomeCenter data.txt");
//English-Spanish data
} else if (DATA_SET == "en-sp") {
Tree::pairedMode = false;
input.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/en-sp/pairs.txt");
//English-German data
} else if (DATA_SET == "en-de") {
Tree::pairedMode = false;
input.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/en-de/10k/pairs.txt");
//German News data
} else if (DATA_SET == "de-news") {
Tree::pairedMode = false;
input.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/de-news/pairs.txt");
} else {
exit(15);
}
// exit(66);
if (input.fail()) {
wcout << "!!!Cannot open the pairs file!!!" << endl;
exit(1);
}
TreePair treePair;
int counter = 1;
TreePair::linked = true;
currentTime = time(0);
// int pairNo = 1; //118
// vector<TreePair> pairs;
while (!input.eof()) {
input >> treePair;
if (!TreePair::error) {
// pairs.push_back(treePair);
// wcout << "size of treePair: " << sizeof(treePair) << endl;
// exit(0);
++counter;
// if (counter <= pairNo) continue;
// wcout << "TreePair №" << counter - 1 << ":" << endl;
// treePair.printXML();
// wcout << treePair;
// wcout << ".";
// wcout << endl;
treePair.removeExtraNodes();
// treePair.printTaggedSentences();
treePair.printSentences();
// treePair.freezeLinks();
// treePair.printBracketed();
// wcout << endl;
// if (counter > pairNo) break;
} else {
wcout << "TreePair №" << counter << ": !!!ERROR!!!" << endl;
}
}
wcout << endl;
// wcout << "Size of pairs: " << << endl;
input.close();
/* chudStopRemotePerfMonitor();
chudReleaseRemoteAccess();*/
currentTime = time(0);
tm* local = localtime(¤tTime);
sec = difftime(currentTime, startTime);
wcout << endl << "Elapsed: " << sec << "sec" << endl;
wcout << "Finished at " << asctime(local);
return 0;
}
示例12: main
//.........这里部分代码省略.........
/*
* Insert the temps in the grid structure with the newTemps array
* Grab the max and min temperatures
*/
for( i = 0; i < numGridBoxes; i++) {
newTemps[i] = grid[i].temp;
}
getMinMax(newTemps, numGridBoxes, &maxTemp, &minTemp);
/*
* Construct the storage box for all threads
* We will be blocking the gridboxes instead of cyclic distribution.
* For example:
* Thread 1: compute grid boxes [0 to (numGridBoxes / numThreads)]
*/
threadStorage *storage = malloc(sizeof(threadStorage) * numThreads);
{
int start;
int spacing = numGridBoxes / numThreads;
for( i = 0, start = 0; i < numThreads; i++, start += spacing ) {
storage[i].id = i;
storage[i].newTemps = &newTemps[start];
storage[i].grid = &grid[start];
storage[i].numGridBoxes = numGridBoxes / numThreads;
}
// Very last thread must pick up the remainder if numGridBoxes/numThreads is not an even integer
storage[numThreads - 1].numGridBoxes += numGridBoxes - (spacing * numThreads);
}
/*
* Time to do the math.
* Compute the AMR Dissipation to convergence
*/
time(&startTime);
clockTime = clock();
while( (maxTemp - minTemp) > (epsilon * maxTemp) ) {
iter++;
/*
* Spawn off all threads
*/
for( i = 0; i < numThreads; i++){
int errno = pthread_create(&threads[i], NULL, threadEntry, &storage[i]);
if( errno ) {
fprintf(stdout, "Iteration %5d | Error creating thread %3d| ERROR: %5d\n", iter, i, errno);
}
}
/*
* Join all threads
*/
for( i = 0; i < numThreads; i++){
int errno = pthread_join(threads[i], NULL);
if( errno ) {
fprintf(stdout, "Iteration %5d | Error joining thread %3d| ERROR: %5d\n", iter, i, errno);
}
}
// Grab the max and min temperatures
getMinMax(newTemps, numGridBoxes, &maxTemp, &minTemp);
// Update the temps in the grid structure with the newTemps array
for( i = 0; i < numGridBoxes; i++) {
grid[i].temp = newTemps[i];
}
}
/*
* Stop the timers
*/
time(&endTime);
clockTime = clock() - clockTime;
printf("*********************************************************************\n");
printf("Num Threads: %3d\n", numThreads);
printf("dissipation converged in %d iterations,\n", iter);
printf("\twith max DSV\t= %lf and min DSV\t= %lf\n", maxTemp, minTemp);
printf("\taffect rate\t= %lf;\tepsilon\t= %lf\n", affectRate, epsilon);
printf("\n");
printf("elapsed convergence loop time\t(clock): %lu\n", clockTime);
printf("elapsed convergence loop time\t (time): %.f\n", difftime(endTime, startTime));
printf("*********************************************************************\n");
/*
* Free the memory of all grid boxes, the temporary 'newTemps' variable, the threads, and the storage box
*/
for( i = 0; i < numGridBoxes; i++ ) {
free(grid[i].neiTemps);
free(grid[i].neiCD);
}
free(grid);
free(newTemps);
free(threads);
free(storage);
return 0;
}
示例13: custom_diff
static
double
custom_diff(time_t t1, time_t t2)
{
return difftime(t1, t2);
}
示例14: curses_draw
static void curses_draw(void)
{
if (NULL == get_current_node()) {
first_node();
first_item();
}
row = 0;
move(0,0);
getmaxyx(stdscr, rows, cols);
if (cols < 80) {
clear();
putl("Screen must be at least 80 columns wide");
refresh();
return;
}
if (c_use_colors)
attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr);
else
attrset(A_REVERSE);
if (get_current_node() && get_current_item()) {
putl(" %s on %s",
get_current_item()->i_name, get_current_node()->n_name);
}
move(row, COLS - strlen(PACKAGE_STRING) - 1);
putl("%s", PACKAGE_STRING);
move(row, 0);
if (c_use_colors)
attrset(COLOR_PAIR(LAYOUT_DEFAULT) | layout[LAYOUT_DEFAULT].attr);
else
attroff(A_REVERSE);
print_content();
if (quit_mode)
print_quit();
else if (print_help) {
if (help_page == 0)
draw_help();
else
draw_help_2();
}
for (; row < rows-2;) {
move(++row, 0);
putl("");
}
row = rows-1;
move(row, 0);
if (c_use_colors)
attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr);
else
attrset(A_REVERSE);
if (1) {
char s[27];
time_t t = time(0);
double d;
int h, m;
asctime_r(localtime(&t), s);
s[strlen(s) - 1] = '\0';
d = difftime(time(0), start_time);
if (d / 3600) {
h = (int) d / 3600;
m = (int) d % 3600;
m /= 60;
} else {
h = 0;
m = (int) d / 60;
}
putl(" %s (%dh/%dm)", s, h, m);
move(row, COLS - strlen("Press ? for help") - 1);
putl("%s", "Press ? for help");
move(row, 0);
}
attrset(0);
refresh();
}
示例15: time
static int set_clock (CalcHandle* handle, CalcClock* _clock)
{
int ret;
uint8_t buffer[9];
uint32_t calc_time;
struct tm ref, cur;
time_t r, c, now;
time(&now); // retrieve current DST setting
memcpy(&ref, localtime(&now), sizeof(struct tm));
ref.tm_year = 1997 - 1900;
ref.tm_mon = 0;
ref.tm_yday = 0;
ref.tm_mday = 1;
ref.tm_wday = 3;
ref.tm_hour = 0;
ref.tm_min = 0;
ref.tm_sec = 0;
//ref.tm_isdst = 1;
r = mktime(&ref);
//printf("%s\n", asctime(&ref));
cur.tm_year = _clock->year - 1900;
cur.tm_mon = _clock->month - 1;
cur.tm_mday = _clock->day;
cur.tm_hour = _clock->hours;
cur.tm_min = _clock->minutes;
cur.tm_sec = _clock->seconds;
cur.tm_isdst = 1;
c = mktime(&cur);
//printf("%s\n", asctime(&cur));
calc_time = (uint32_t)difftime(c, r);
buffer[0] = 0;
buffer[1] = 0;
buffer[2] = MSB(MSW(calc_time));
buffer[3] = LSB(MSW(calc_time));
buffer[4] = MSB(LSW(calc_time));
buffer[5] = LSB(LSW(calc_time));
buffer[6] = _clock->date_format;
buffer[7] = _clock->time_format;
buffer[8] = 0xff;
ticalcs_strlcpy(handle->updat->text, _("Setting clock..."), sizeof(handle->updat->text));
ticalcs_update_label(handle);
ret = SEND_RTS(handle, 13, TI73_CLK, "\0x08\0\0\0\0\0\0\0", 0x00, 0x00);
if (!ret)
{
ret = RECV_ACK(handle, NULL);
if (!ret)
{
ret = RECV_CTS(handle, 13);
if (!ret)
{
ret = SEND_ACK(handle);
if (!ret)
{
ret = SEND_XDP(handle, 9, buffer);
if (!ret)
{
ret = RECV_ACK(handle, NULL);
if (!ret)
{
ret = SEND_EOT(handle);
}
}
}
}
}
}
return ret;
}