本文整理汇总了C++中GetTimeMs函数的典型用法代码示例。如果您正苦于以下问题:C++ GetTimeMs函数的具体用法?C++ GetTimeMs怎么用?C++ GetTimeMs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetTimeMs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PerftTest
void PerftTest(int depth, S_BOARD *pos) {
S_MOVELIST list[1];
int move;
int MoveNum = 0;
int start = GetTimeMs();
long cumnodes, oldnodes;
ASSERT(CheckBoard(pos));
PrintBoard(pos);
printf("\nStarting Test To Depth:%d\n", depth);
leafNodes = 0;
GenerateAllMoves(pos, list);
for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
move = list->moves[MoveNum].move;
if(!MakeMove(pos, move))
continue;
cumnodes = leafNodes;
Perft(depth - 1, pos);
TakeMove(pos);
oldnodes = leafNodes - cumnodes;
printf("move %d : %s : %ld\n", MoveNum + 1, PrMove(move), oldnodes);
}
printf("\nTest Complete : %ld nodes visited in %dms\n", leafNodes, GetTimeMs() - start);
}
示例2: tcp_client
void* tcp_client(void *whatever){
struct sockaddr_in server_addr;
int sckt, status, len;
int starttime, stoptime;
struct hostent *server;
int iSetOption = 1;
sckt = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
setsockopt(sckt, SOL_SOCKET, SO_REUSEADDR, (char*)&iSetOption, sizeof(iSetOption));
if(sckt == -1)
{
printf("error opening socket\n");
exit(EXIT_FAILURE);
}
if (h.server == NULL) {
fprintf(stderr,"Cannot connect to the server\n");
exit(EXIT_FAILURE);
}
server_addr.sin_port = htons(h.port);
memcpy(&server_addr.sin_addr.s_addr, h.server->h_addr, h.server->h_length);
server_addr.sin_family = AF_INET;
if (connect(sckt,(struct sockaddr *) &server_addr,sizeof(server_addr)) < 0) {
printf("Couldn't connect\n");
exit(EXIT_FAILURE);
}
starttime = GetTimeMs();
status = write(sckt, h.buffer, lSize);
if (status < 0){
printf("Couldn't write the message\n");
exit(EXIT_FAILURE);
}
stoptime = GetTimeMs();
printf("Duration client write = %d us\n", stoptime - starttime);
//sleep(2);
starttime = GetTimeMs();
char *message = (char *)calloc( 1, lSize+1 );
status = read(sckt,message,lSize);
if (status < 0){
printf("Cannot read from the socket\n");
exit(EXIT_FAILURE);
}
stoptime = GetTimeMs();
printf("Duration client read back = %d us\n", stoptime - starttime);
//printf("%s\n", message);
close(sckt);
pthread_exit(NULL);
exit(EXIT_SUCCESS);
}
示例3: DisplaySubWindow
// Callback function called by GLUT to render sub-window content
void DisplaySubWindow(void)
{
float v[4]; // will be used to set light parameters
float mat[4*4]; // rotation matrix
SubWindowData *win;
win = GetCurrentSubWindowData();
if (win == NULL) return;
// Tell AntTweakBar which is the current window
TwSetCurrentWindow(win->WinID);
// Clear frame buffer
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_NORMALIZE);
// Set light
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
v[0] = v[1] = v[2] = win->LightMultiplier*0.4f; v[3] = 1.0f;
glLightfv(GL_LIGHT0, GL_AMBIENT, v);
v[0] = v[1] = v[2] = win->LightMultiplier*0.8f; v[3] = 1.0f;
glLightfv(GL_LIGHT0, GL_DIFFUSE, v);
v[0] = -win->LightDirection[0]; v[1] = -win->LightDirection[1]; v[2] = -win->LightDirection[2]; v[3] = 0.0f;
glLightfv(GL_LIGHT0, GL_POSITION, v);
// Set material
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, win->MatAmbient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, win->MatDiffuse);
// Rotate and draw shape
glPushMatrix();
glTranslatef(0.5f, -0.3f, 0.0f);
if( win->AutoRotate )
{
float axis[3] = { 0, 1, 0 };
float angle = (float)(GetTimeMs()-win->RotateTime)/1000.0f;
float quat[4];
SetQuaternionFromAxisAngle(axis, angle, quat);
MultiplyQuaternions(win->RotateStart, quat, win->Rotation);
}
ConvertQuaternionToMatrix(win->Rotation, mat);
glMultMatrixf(mat);
glScalef(win->Zoom, win->Zoom, win->Zoom);
glCallList(win->ObjectShape);
glPopMatrix();
// Draw tweak bars
TwDraw();
// Present frame buffer
glutSwapBuffers();
// Recall Display at next frame
glutPostRedisplay();
}
示例4: DebugAnalysisTest
void DebugAnalysisTest(S_BOARD *pos, S_SEARCHINFO *info) {
FILE *file;
file = fopen("lct2.epd","r");
char lineIn [1024];
info->depth = MAXDEPTH;
info->timeset = TRUE;
int time = 1140000;
if(file == NULL) {
printf("File Not Found\n");
return;
} else {
while(fgets (lineIn , 1024 , file) != NULL) {
info->starttime = GetTimeMs();
info->stoptime = info->starttime + time;
ClearHashTable(pos->HashTable);
ParseFen(lineIn, pos);
printf("\n%s\n",lineIn);
printf("time:%d start:%d stop:%d depth:%d timeset:%d\n",
time,info->starttime,info->stoptime,info->depth,info->timeset);
SearchPosition(pos, info);
memset(&lineIn[0], 0, sizeof(lineIn));
}
}
}
示例5: return
// Get the time elapsed since the Start()
u64 Timer::GetTimeElapsed()
{
// If we have not started yet, return 1 (because then I don't
// have to change the FPS calculation in CoreRerecording.cpp .
if (m_StartTime == 0) return 1;
// Return the final timer time if the timer is stopped
if (!m_Running) return (m_LastTime - m_StartTime);
return (GetTimeMs() - m_StartTime);
}
示例6: IB_Animate_Sleep
static void
IB_Animate_Sleep(unsigned int t0, double a)
{
unsigned int t;
double dt;
t = GetTimeMs() - t0;
dt = 1e-3 * (t - a * IB_ANIM_TIME);
dt = 1e-3 * IB_ANIM_STEP - dt;
if (dt > 0)
usleep((unsigned long)(1e6 * dt));
}
示例7: SetAutoRotateCB
void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
{
g_AutoRotate = *(const int *)value;
if (g_AutoRotate != 0)
{
g_RotateTime = GetTimeMs();
g_RotateStart[0] = g_Rotation[0];
g_RotateStart[1] = g_Rotation[1];
g_RotateStart[2] = g_Rotation[2];
g_RotateStart[3] = g_Rotation[3];
TwDefine(" TweakBar/ObjRotation readonly ");
}
else
TwDefine(" TweakBar/ObjRotation readwrite ");
}
示例8: SetAutoRotateCB
// Callback function called when the 'AutoRotate' variable value of the tweak bar has changed
void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
{
(void)clientData; // unused
g_AutoRotate = *(const int *)value; // copy value to g_AutoRotate
if (g_AutoRotate != 0)
{
// init rotation
g_RotateTime = GetTimeMs();
g_RotateStart[0] = g_Rotation[0];
g_RotateStart[1] = g_Rotation[1];
g_RotateStart[2] = g_Rotation[2];
g_RotateStart[3] = g_Rotation[3];
// make Rotation variable read-only
TwDefine(" TweakBar/ObjRotation readonly ");
}
else
// make Rotation variable read-write
TwDefine(" TweakBar/ObjRotation readwrite ");
}
示例9: SetAutoRotateCB
// Callback function called when the 'AutoRotate' variable value of the tweak bar has changed
void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
{
SubWindowData *win;
win = (SubWindowData *)clientData;
win->AutoRotate = *(const int *)value; // copy value to win->AutoRotate
if (win->AutoRotate != 0)
{
// init rotation
win->RotateTime = GetTimeMs();
win->RotateStart[0] = win->Rotation[0];
win->RotateStart[1] = win->Rotation[1];
win->RotateStart[2] = win->Rotation[2];
win->RotateStart[3] = win->Rotation[3];
}
// make Rotation variable read-only or read-write
TwSetCurrentWindow(win->WinID);
TwSetParam(win->Bar, "ObjRotation", "readonly", TW_PARAM_INT32, 1, &win->AutoRotate);
}
示例10: GetTimeMs
// Get the formatted time elapsed since the Start()
std::string Timer::GetTimeElapsedFormatted() const
{
// If we have not started yet, return zero
if (m_StartTime == 0)
return "00:00:00:000";
// The number of milliseconds since the start.
// Use a different value if the timer is stopped.
u64 Milliseconds;
if (m_Running)
Milliseconds = GetTimeMs() - m_StartTime;
else
Milliseconds = m_LastTime - m_StartTime;
// Seconds
u32 Seconds = (u32)(Milliseconds / 1000);
// Minutes
u32 Minutes = Seconds / 60;
// Hours
u32 Hours = Minutes / 60;
std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i",
Hours, Minutes % 60, Seconds % 60, Milliseconds % 1000);
return TmpStr;
}
示例11: overlap
void overlap() {
Globals::qbs = new QNode*[Globals::threads_num];
Globals::sets = new std::map<myset,myset*>[Globals::threads_num];
for (int i = 0; i<Globals::threads_num; i++) {
Globals::qbs[i] = new QNode();
}
denominator = Globals::c2 * Globals::gamma;
denominator /= Globals::side_multiplier;
boost::thread* thr[Globals::threads_num];
for (int i = 0; i < Globals::threads_num; ++i)
thr[i] = new boost::thread(Worker(i));
for (int i = 0; i < Globals::threads_num; ++i) {
thr[i]->join();
delete thr[i];
}
// for (int i=0; i<Globals::threads_num; i++) {
// rec_count(Globals::qbs[i], 1.0);
// std::cout << Globals::ov_nodes << " " << Globals::ov_leaves << std::endl;
// Globals::ov_nodes=1;
// Globals::ov_leaves=0;
// }
double merging_timer = GetTimeMs();
for (int i=1; i<Globals::threads_num; i++) {
std::cout << "Merging " << i << std::endl;
merge_nodes(Globals::qbs[0],Globals::qbs[i]);
delete Globals::qbs[i];
}
Globals::qb = Globals::qbs[0];
//depth_all_reprs(Globals::qb);
make_it_deeper(Globals::qb);
//TODO
//std::cout << "start filling" << std::endl;
// std::cout << "before fill vectors" << std::endl;
// fill_vectors(Globals::qb, &Globals::hypercube_center, 1.0);
/* for (int i=0; i<10; i++) {
printPt(std::cout,*Globals::qt_centers[i]);
std::cout<<std::endl;
std::cout << Globals::qt_sides[i] << std::endl;
}*/
Globals::ov_nodes=1;
Globals::ov_leaves=0;
rec_count(Globals::qb);
//TODO
////std::cout << " ovnodes " << Globals::ov_nodes << " " << Globals::ov_leaves << std::endl;
////std::cout << "LEAF: " << couter << std::endl;
dothereprs();
ANNmin_k* asdf = new ANNmin_k(1);
// fill_in_reprs(Globals::qb, &Globals::hypercube_center, 1.0, Globals::kdtree, asdf);
find_all_reprs(Globals::qbs[0], &Globals::hypercube_center, 1.0, Globals::kdtree, asdf,0);
Globals::merging_time = GetTimeMs() - merging_timer;
ANNidxArray nnIdx = new ANNidx[Globals::reprs_num];
ANNdistArray dists = new ANNdist[Globals::reprs_num];
//replace_reprs(Globals::qb, &Globals::hypercube_center, 1.0, nnIdx, dists); CHANGE
delete[] nnIdx;
delete[] dists;
//TODO
// std::cout << "done replacing" << std::endl;
/*std::map<myset,myset*>::iterator it;
for (int i=0; i<Globals::threads_num; i++) {
for (it=Globals::sets[i].begin(); it!=Globals::sets[i].end(); it++) {
delete (*it).second;
}
}*/
delete[] Globals::sets;
//representatives();
}
示例12: printf
void IO::consoleLoop(Board* board, SEARCHINFO* info) {
printf("Welcome to TidesTicTactics in Console Mode!\n");
info->POST_THINKING = true;
setbuf(stdin, NULL);
setbuf(stdin, NULL);
int depth = 81;
int movetime = 500; // 3 sec
Coordinate move;
char inBuf[80], command[80], modifier[80];
Color engineSide = COLOR_NONE;
Engine engine;
Movelist movecheck;
bool init = false;
bool initX = true;
Movelist movelist;
while (true) {
fflush(stdout);
if ((board->toMove == engineSide || engineSide == COLOR_BOTH) && board->winner == COLOR_NONE) {
info->starttime = GetTimeMs();
info->depth = depth;
if (movetime != 0) {
info->timeset = true;
info->stoptime = info->starttime + movetime;
}
engine.searchPosition(board, info, true);
engineSide = COLOR_NONE;
}
// print prompt
printf("");
fflush(stdout);
memset(&inBuf[0], 0, sizeof(inBuf));
fflush(stdout);
if(!fgets(inBuf, 80, stdin))
continue;
std::transform(inBuf, inBuf + 80 - 1, inBuf, [](unsigned char c) { return std::tolower(c); });
sscanf(inBuf, "%s", command);
if(!strcmp(command, "help")) {
printf("\nCommands:\n");
printf("quit - quit game\n");
printf("force - will not move\n");
printf("print - show board\n");
printf("post - show thinking\n");
printf("nopost - do not show thinking\n");
printf("new - start new game\n");
printf("go - set computer thinking\n");
printf("depth x - set depth to x\n");
printf("time x - set thinking time to x seconds (depth still applies if set)\n");
printf("view - show current depth and movetime settings\n");
printf("moves - show valid moves\n");
printf("captures - show moves winning a board");
printf("test x - load first x moves of demo");
printf("test2 x - load first x moves of demo");
printf("** note ** - to reset time and depth, set to 0\n");
printf("enter moves using B1..9F1..9 notation\n\n\n");
continue;
}
if(!strcmp(command, "moves")) {
board->getMoves(&movecheck);
if (movecheck.count == 0) {
printf("No moves found");
}
for(int i = 0; i < movecheck.count; i++) {
printf("%s ", PRMOVE(movecheck.moves[i].move).c_str());
}
printf("\n");
continue;
}
if(!strcmp(command, "player")) {
sscanf(inBuf, "player %s init", modifier);
if(!strcmp(modifier, "one")) {
init = true;
initX = true;
} else if(!strcmp(modifier, "two")) {
init = true;
initX = false;
} else {
printf("unknown player: %s\n", modifier);
}
continue;
}
if(!strcmp(command, "start")) {
sscanf(inBuf, "start %s", modifier);
if(!strcmp(modifier, "turns")) {
init = false;
board->toMove = COLOR_X;
board->next = SQUARE_NONE;
} else if(!strcmp(modifier, "game")) {
init = true;
} else {
printf("unknown start modifier: %s\n", modifier);
}
continue;
}
if(!strcmp(command, "captures")) {
//.........这里部分代码省略.........
示例13: main
//.........这里部分代码省略.........
glutCreateWindow("SRTP Middle Check");
glutCreateMenu(NULL);
glewInit();
initTextureList();
for (int i = 0; i < textpoint; i++){
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, textureObjects[i]);
}
glActiveTexture(GL_TEXTURE0);
sprintf(path, "%sCook-Torrorence", root);
programs[2] = setupShaders(path);
// Set GLUT callbacks
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
// Initialize AntTweakBar
TwInit(TW_OPENGL, NULL);
// Set GLUT event callbacks
// - Directly redirect GLUT mouse button events to AntTweakBar
glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
// - Directly redirect GLUT mouse motion events to AntTweakBar
glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
// - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
// - Directly redirect GLUT key events to AntTweakBar
glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
// - Directly redirect GLUT special key events to AntTweakBar
glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
// - Send 'glutGetModifers' function pointer to AntTweakBar;
// required because the GLUT key event functions do not report key modifiers states.
TwGLUTModifiersFunc(glutGetModifiers);
// Create some 3D objects (stored in display lists)
glNewList(SHAPE_TEAPOT, GL_COMPILE);
glutSolidTeapot(1.0);
glEndList();
glNewList(SHAPE_TORUS, GL_COMPILE);
//glutSolidTorus(0.3, 1.0, 16, 32);
glutSolidSphere(0.75f, 20, 20);
glEndList();
glNewList(SHAPE_DRAGON, GL_COMPILE);
drawBunny("dragon");
glEndList();
glNewList(SHAPE_SKULL, GL_COMPILE);
drawBunny("skull");
glEndList();
glNewList(SHAPE_GARGO, GL_COMPILE);
drawBunny("Gargoyle_ABF");
glEndList();
glNewList(DRAW_EN, GL_COMPILE);
drawEnv(30);
glEndList();
// Create a tweak bar
bar = TwNewBar("TweakBar");
TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
TwDefine(" TweakBar size='250 540' color='96 216 224' "); // change default tweak bar size and color
TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=7.5 step=0.01 ");
TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, " label='Object rotation' opened=true ");
TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, " label='Auto-rotate' key=space ");
TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &lightDirection, " label='Light direction' opened=true ");
TwAddVarRW(bar, "LightDist", TW_TYPE_FLOAT, &lightDistance, " label='Light distance' ");
TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &lightAmbient, "");
TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &lightDiffuse, "");
TwAddVarRW(bar, "Rf", TW_TYPE_COLOR3F, &rf, "");
TwAddVarRW(bar, "Roughness", TW_TYPE_FLOAT, &roughness, " label='Roughness' min=0.01 max=1.99 step=0.01 keyIncr='+' keyDecr='-' ");
{
TwEnumVal shaders[NUM_SHADERS] = { { SHADER_PHONG, "Phong" }, { SHADER_COOKTORRORENCE, "CookTorrorence" } };
TwType shaderType = TwDefineEnum("ShaderType", shaders, NUM_SHADERS);
TwAddVarRW(bar, "Shader", shaderType, ¤tShader, "");
}
// Add the enum variable 'g_CurrentShape' to 'bar'
// (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
{
// ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
TwEnumVal shapeEV[NUM_SHAPES] = { { SHAPE_TEAPOT, "Teapot" }, { SHAPE_TORUS, "Sphere" }, { SHAPE_DRAGON, "Dragon" }, { SHAPE_SKULL, "Skull" }, { SHAPE_GARGO, "Gargo" } };
// Create a type for the enum shapeEV
TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
// add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, "");
}
// Store time
g_RotateTime = GetTimeMs();
// Init rotation
SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);
atexit(Terminate); // Called after glutMainLoop ends
// Call the GLUT main loop
glutMainLoop();
return 0;
}
示例14: main
int main() {
// Create the variables for the time measure
int starttime, stoptime;
//Get initial time
starttime = GetTimeMs();
// This code executes on the OpenCL host
// Host data
float *A=NULL; // Input array
float *B=NULL; // Input array
float *C=NULL; // Output array
// Elements in each array
const int elements=2048;
// Compute the size of the data
size_t datasize=sizeof(int)*elements;
// Allocate space for input/output data
A=(float*)malloc(datasize);
B=(float*)malloc(datasize);
C=(float*)malloc(datasize);
// Initialize the input data
A[0]=2.2;
A[1]=1.3;
B[0]=3.7;
B[1]=5.4;
// Load the kernel source code into the array programSource
FILE *fp;
char *programSource;
size_t programSize;
fp = fopen("fplos_kernels.cl", "r");
if (!fp) {
fprintf(stderr, "Failed to load kernel.\n");
exit(1);
}
programSource = (char*)malloc(MAX_SOURCE_SIZE);
fclose( fp );
// Use this to check the output of each API call
cl_int status;
// Retrieve the number of platforms
cl_uint numPlatforms=0;
status=clGetPlatformIDs(0, NULL,&numPlatforms);
// Allocate enough space for each platform
cl_platform_id *platforms=NULL;
platforms=(cl_platform_id*)malloc(
numPlatforms*sizeof(cl_platform_id));
// Fill in the platforms
status = clGetPlatformIDs(numPlatforms, platforms, NULL);
// Retrieve the number of devices
cl_uint numDevices=0;
status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL, 0,
NULL,&numDevices);
// Allocate enough space for each device
cl_device_id *devices;
devices = (cl_device_id*)malloc(
numDevices*sizeof(cl_device_id));
// Fill in the devices
status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL,
numDevices, devices, NULL);
// Create a context and associate it with the devices
cl_context context;
context = clCreateContext(NULL, numDevices, devices, NULL,
NULL, &status);
// Create a command queue and associate it with the device
cl_command_queue cmdQueue;
cmdQueue = clCreateCommandQueue(context, devices[0], 0,
&status);
// Create a buffer object that will contain the data
// from the host array A
cl_mem bufA;
bufA = clCreateBuffer(context, CL_MEM_READ_ONLY, datasize,
NULL, &status);
// Create a buffer object that will contain the data
// from the host array B
cl_mem bufB;
bufB = clCreateBuffer(context, CL_MEM_READ_ONLY, datasize,
NULL, &status);
// Create a buffer object that will hold the output data
cl_mem bufC;
bufC = clCreateBuffer(context, CL_MEM_WRITE_ONLY, datasize,
NULL, &status);
//.........这里部分代码省略.........
示例15: main
int main(int argc, char *argv[]){
int t1,t2;
int starttime, stoptime;
pthread_t thread1, thread2;
h.server = gethostbyname(argv[1]);
h.port = atoi(argv[2]);
FILE *fp;
if(strcmp(argv[3], "1b") == 0)fp = fopen("../txt/1b.txt", "rb");
else if(strcmp(argv[3], "1kb") == 0)fp = fopen("../txt/1kb.txt", "rb");
else if(strcmp(argv[3], "64kb") == 0)fp = fopen("../txt/64kb.txt", "rb");
else if(strcmp(argv[3], "1mb") == 0)fp = fopen("../txt/1mb.txt", "rb");
else fp = fopen("../txt/alice.txt", "rb");
if (!fp) {
fprintf(stderr, "Failed to load file.\n");
return -1;
}
fseek( fp , 0L , SEEK_END);
lSize = ftell( fp );
rewind( fp );
/* allocate memory for entire content */
h.buffer = (char *)calloc( 1, lSize+1 );
if( !h.buffer ){
fclose(fp);
printf("Couldn't allocate memory\n");
return -1;
}
/* copy the file into the buffer */
if( fread( h.buffer , lSize, 1 , fp) != true){
fclose(fp);
free(h.buffer);
printf("Couldn't copy in buffer\n");
return -1;
}
fclose(fp);
const char *message1 = "Thread 1";
const char *message2 = "Thread 2";
starttime = GetTimeMs();
t1 = pthread_create(&thread1, NULL, tcp_server, (void *)message1);
if (t1) {
printf("ERROR; thread tcp_server");
return -1;
}
t2 = pthread_create(&thread2, NULL, tcp_client, (void *)message2);
if (t2) {
printf("ERROR; thread tcp_client");
return -1;
}
stoptime = GetTimeMs();
//printf("Duration= %d us\n", stoptime - starttime);
pthread_exit(NULL);
return 0;
}