mmap测试

#include "mmap_fstream.h"
#include "log.h"
#include <iostream>
#include <ostream>
#include <string.h>
#include <fstream>
#include <time.h>
#include <sys/stat.h>
#include <sys/timeb.h>
#include <fcntl.h>

using namespace std;
using namespace log4cplus;
using namespace log4cplus::helpers;

static Logger logger;

void InitLog();

int main(){

//	InitLog();
	string file_name("mmap_file.txt");
	MMapStream out_stream(file_name.c_str());
//	ofstream out_stream(file_name.c_str());


	struct timeb start_time;
	struct timeb end_time;
	ftime(&start_time);
	uint32_t loop_times = 40000000;
	for(int i = 0; i < loop_times; i++){

//		for(int j = 0; j < loop_times; j++){
//
//			char* buf = "test";
//			char* buff = new char[4];
//			memcpy(buff,buf, strlen(buff));
//			delete[] buff;
//			buff = NULL;
//		}
		char* buffer = "liyongggggggggggggggggggggggg";
		out_stream.write(buffer, strlen(buffer));
	}
	ftime(&end_time);
	cout << "start_time is: " << start_time.millitm << endl;
	cout << "end_time is: " <<  end_time.millitm << endl;
	cout << "time is: " << end_time.millitm - start_time.millitm  << endl;
//	mmap_stream.seekp(4095);
//	std::streamoff current_off = mmap_stream.tellp();
//	char buffer1[] = "liyong";
//	mmap_stream.write(buffer1, strlen(buffer1));
//	char buffer2[] = "LIYONG";
//	mmap_stream.write(buffer2, strlen(buffer2));

//	int fd = open("mmap_file.txt",O_CREAT | O_RDWR, 0644);
//	lseek(fd, 4095, SEEK_SET);
//	char* buf = new char[6];
//	read(fd, buf, 6);
//	cout << string(buf) << endl;
//
//	lseek(fd, 5002, SEEK_SET);
//	read(fd, buf, 5);
//	cout << string(buf) << endl;



}


你可能感兴趣的:(String,struct,Stream,File,buffer,include)