- 浏览: 595943 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
月光杯:
问题解决了吗?
Exceptions in HDFS -
iostreamin:
神,好厉害,这是我找到的唯一可以ac的Java代码,厉害。
[leetcode] word ladder II -
standalone:
One answer I agree with:引用Whene ...
How many string objects are created? -
DiaoCow:
不错!,一开始对这些确实容易犯迷糊
erlang中的冒号 分号 和 句号 -
standalone:
Exception in thread "main& ...
one java interview question
/* * Test performance of allocating a zeroed file via various methods on * various file systems * * Copyright (C) 2009 Red Hat Inc. * Author(s): Amit Shah * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> #include <fcntl.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <asm/unistd.h> #include <sys/time.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/mount.h> #include <sys/mman.h> #define GB(x) ((unsigned long long)x << 30) int pre_test_setup(char *source, char *target, char *fstype, unsigned long mntflags, char *mntopts, char *name, int *fd) { int r; if (source) { r = mount(source, target, fstype, mntflags, mntopts); if (r < 0) { perror("mount"); return -1; } } unlink(name); *fd = open(name, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if (*fd < 0) { perror("open"); return -1; } /* Flush out all other data that might be pending writing to * the disk. We don't want to count the time we wait for the * buffers of other apps to clear. (Ideally, this test would * be run in single user mode with nothing else running on the * system.) */ sync(); sync(); /* Just to be sure - http://lwn.net/Articles/325420/ */ sync(); return 0; } int post_test_cleanup(char *target, int *fd) { int r; r = close(*fd); if (r < 0) perror("close"); if (strcmp(target, ".")) { r = umount(target); if (r < 0) perror("unmount"); } return r; } void run_test(int (test)(char *, int *, off_t, size_t), char *source, char *target, char *fstype, unsigned long mntflags, char *mntopts, char *filename, off_t len, size_t data) { int r, fd; r = pre_test_setup(source, target, fstype, mntflags, mntopts, filename, &fd); if (r < 0) goto error_exit; (test)(target, &fd, len, data); return; error_exit: post_test_cleanup(target, &fd); return; } int do_posix_fallocate(char *target, int *fd, off_t len, size_t data) { int r; struct timeval tv1, tv2; printf("posix-fallocate run time:\n"); gettimeofday(&tv1, NULL); r = posix_fallocate(*fd, 0, len); post_test_cleanup(target, fd); gettimeofday(&tv2, NULL); if (r < 0) { printf("posix_fallocate, error %d\n", r); return r; } printf("\tseconds:microseconds: %llu:%llu\n", tv1.tv_sec, tv1.tv_usec); printf("\tseconds:microseconds: %llu:%llu\n", tv2.tv_sec, tv2.tv_usec); printf("\t(approx %us)\n", tv2.tv_sec - tv1.tv_sec); return 0; } int do_fallocate(char *target, int *fd, off_t len, size_t data) { int r; struct timeval tv1, tv2; printf("fallocate run time:\n"); gettimeofday(&tv1, NULL); r = syscall(__NR_fallocate, *fd, 0, len); post_test_cleanup(target, fd); gettimeofday(&tv2, NULL); if (r < 0) { perror("fallocate"); return r; } printf("\tseconds:microseconds: %llu:%llu\n", tv1.tv_sec, tv1.tv_usec); printf("\tseconds:microseconds: %llu:%llu\n", tv2.tv_sec, tv2.tv_usec); printf("\t(approx %us)\n", tv2.tv_sec - tv1.tv_sec); return 0; } int do_mmap(char *target, int *fd, off_t len, size_t data) { struct timeval tv1, tv2; char *addr; /* memset has to have the mmap'ed file backed by something on * disk -- bus error otherwise */ ftruncate(*fd, len); addr = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, *fd, 0); if (addr == MAP_FAILED) { perror("mmap"); return -2; } printf("mmap run time:\n"); gettimeofday(&tv1, NULL); memset(addr, 0, len); munmap(addr, len); post_test_cleanup(target, fd); gettimeofday(&tv2, NULL); printf("\tseconds:microseconds: %llu:%llu\n", tv1.tv_sec, tv1.tv_usec); printf("\tseconds:microseconds: %llu:%llu\n", tv2.tv_sec, tv2.tv_usec); printf("\t(approx %us)\n", tv2.tv_sec - tv1.tv_sec); return 0; } int do_write_chunks(char *target, int *fd, off_t len, size_t data) { struct timeval tv1, tv2; unsigned long long remain = len; char *zeros; zeros = calloc(1, data); printf("%llu-sized chunk run time:\n", data); gettimeofday(&tv1, NULL); while (remain) { int bytes = data; if (bytes > remain) bytes = remain; if ((bytes = write(*fd, zeros, bytes)) < 0) { perror("write"); return -2; } remain -= bytes; } post_test_cleanup(target, fd); gettimeofday(&tv2, NULL); printf("\tseconds:microseconds: %llu:%llu\n", tv1.tv_sec, tv1.tv_usec); printf("\tseconds:microseconds: %llu:%llu\n", tv2.tv_sec, tv2.tv_usec); printf("\t(approx %us)\n", tv2.tv_sec - tv1.tv_sec); free(zeros); return 0; } int main(int argc, char **argv) { char *source, *target, *fstype, *mntopts; char filename[200]; unsigned long mntflags; unsigned long long filesize; /* FIXME! use getopt */ if (argc < 2 || argc > 2 && argc < 5) { printf("usage: %s <filesize-in-gb> <device> <mountpoint> <fstype> [mntflags] [mntopts]\n", argv[0]); return -1; } filesize = GB(atol(argv[1])); if (argc > 2) { source = argv[2]; target = argv[3]; fstype = argv[4]; } else { source = NULL; target = "."; fstype = "native"; } if (argc > 5) mntflags = atol(argv[5]); else mntflags = 0; if (argc > 6) mntopts = argv[6]; else mntopts = NULL; sprintf(filename, "%s/%s-pf", target, fstype); run_test(do_posix_fallocate, source, target, fstype, mntflags, mntopts, filename, filesize, 0); #if 0 sprintf(filename, "%s/%s-fallocate", target, fstype); run_test(do_fallocate, source, target, fstype, mntflags, mntopts, filename, filesize, 0); #endif sprintf(filename, "%s/%s-mmap", target, fstype); run_test(do_mmap, source, target, fstype, mntflags, mntopts, filename, filesize, 0); sprintf(filename, "%s/%s-chunk4k", target, fstype); run_test(do_write_chunks, source, target, fstype, mntflags, mntopts, filename, filesize, 4 * 1024); sprintf(filename, "%s/%s-chunk8k", target, fstype); run_test(do_write_chunks, source, target, fstype, mntflags, mntopts, filename, filesize, 8 * 1024); return 0; }
发表评论
-
std::map
2017-08-06 22:41 577std::map<char,int> my ... -
lost on Py_DECREF/INCREF when handling PyList_Append in Python C extension
2015-11-03 21:41 1011The main hint is in the docs, i ... -
An Example of Using std::tr1::bind
2014-03-10 16:49 1479#include <iostream> #i ... -
c++中的virtual inheritance
2014-01-27 10:20 758http://stackoverflow.com/questi ... -
Java的Generics和c++的Template到底有什么不同?
2012-12-27 16:21 3185先了解Java的Generics: 根据Java的文档,Jav ... -
Calculating Permutations and Job Interview Questions
2011-06-18 17:44 911http://www.bearcave.com/random_ ... -
字符串指针、字符数组的sizeof和strlen结果
2010-09-27 08:36 1421int main(){ char *p1=" ... -
code snippet
2010-09-27 08:31 888char temp[3]; char temp2[3]; ... -
虚继承
2010-09-26 09:03 927http://www.cppblog.com/franksun ... -
调整堆的算法
2010-09-25 10:34 1113Begin adjustHeap(A[], i) // He ... -
multiset usage as heap
2010-09-24 21:37 1413Middle number There is a seque ... -
虚函数表又是怎样实现的?
2010-09-20 22:01 1285每个含有虚函数的类 ... -
正整数分解算法
2010-09-19 16:56 3987问题:将以正整数n表 ... -
异或运算法则
2010-09-14 09:47 21451. a ^ b = b ^ a 2 ... -
常量字符串为什么位于静态存储区
2010-09-13 22:41 1205http://hi.baidu.com/%D0%C7%BB%F ... -
errno.h
2010-08-10 08:46 1466查看错误代码errno是调试程序的一个重要方法。当linuc ... -
How to use fallocate system call
2010-08-07 22:19 3397/* * fallocate - utility to u ... -
how to reverse the word sequence in a sentence?
2010-07-06 22:01 1197For example, "Welcome ... -
c++ dynamic binding
2010-07-06 21:20 865Good tutorial about c++ dynamic ... -
deep copy & shallow copy
2010-07-06 20:57 1075A shallow copy of an object c ...
相关推荐
A hard page fault results in a read from disk, either a page file or memory-mapped file. A soft page fault is resolved from one of the modified, standby, free or zero page transition lists. Paging is...
Typical services include executing a new program, opening a file, reading a file, allocating a region of memory, getting the current time of day, and so on. The focus of this text is to describe the ...
C++的编译器
a highly efficient proprietary HttpModule, which enables uploading of files with size up to 2GB, while allocating a minimum amount of server memory. UI control for single- and multi-file uploads, ...
Fig01_02.cpp: A simple recursive routine with a test program Fig01_03.cpp: An example of infinite recursion Fig01_04.cpp: Recursive routine to print numbers, with a test program Fig01_05.cpp: ...
Allocating fixed costs or resources and setting targets via data envelopment analysis
Allocating fixed costs and common revenue via data envelopment analysis
The Form of a Subclass Definition 117 Overriding Superclass Methods 119 Instance Variables 119 Entry and Exit Points 121 Initialize or Decode? 122 Storing and Accessing Properties 123 Key-Value ...
In this paper we examine the question of designing and allocating transmission sequences to users in a mobile ad hoc network that has no spatially boundary. A basic tenet of the transmission sequence ...
18.3 Allocating arrays 487 18.4 Utility functions 488 18.5 Organizing input data 495 18.6 Configuration snapshot files 498 18.7 Managing extensive computations 500 18.8 Header files 504 19 The future ...
Allocating Storage for Multidimensional Arrays 5.6.2.4 - Accessing Multidimensional Array Elements in Assembly Language 5.6.3 - Structures 5.6.4 - Arrays of Structures and Arrays/Structures ...
3-2 Allocating a portion of the LBP size to LOCKLIST 3-3 Avoid lock escalation with GLM Size 3-4 PAGE_AGE_TRGT_GCR – Improve Performance but also Increases Recovery time 3-5 Setting the correct ...
Note: allocating a very large buffer size under Windows 95/98/Me can take a minute. <br>Max Phase <br>Specifies the maximum number of bytes that will be captured on each phase. Example: if Max ...
10.2.2 Contents of a Class File 399 10.2.3 JVM Instructions 401 10.3 Static Single Assignment Form 410 10.3.1 Renaming and φ-functions 411 10.4 Exercises 414 11 Code Generation for a Virtual Machine ...
Lua is a small and simple language, partly because it does not try to do what C is already good for, such as sheer performance and interface with third-party software. Lua relies on C for these tasks...
Using the vulnerability of allocating the large heap without randomness, we can leak any object address allocated in jscript9 custom heap, and bypass ASLR in Internet Explorer on Windows 7/8/8.1.
Allocating and Returning Objects from Methods 146 Extending Class Definitions and the Interface File 148 Exercises 148 8 Inheritance 151 It All Begins at the Root 151 Finding the Right Method 155 ...
A Bit of History Building A DLL Easing the Build Process Using Dynamic-link Libraries with C++ Name Mangling Alternative Calling Conventions Using and Writing DLLs with MFC MFC DLL Models ...
Only small packets are copied on reception because creating a copy is more efficient than allocating a new buffer. TCP, UDP and IPv4 checksum offload (receive and transmit). Support for TCP/IPv6 and ...
allocating frame slots, and each tag generates a random sequence in its own reservation slot randomly selected by this tag to reserve a frame slot, then the reader efficiently captures the reservation...