- 浏览: 611182 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
月光杯:
问题解决了吗?
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 616std::map<char,int> my ... -
lost on Py_DECREF/INCREF when handling PyList_Append in Python C extension
2015-11-03 21:41 1059The main hint is in the docs, i ... -
An Example of Using std::tr1::bind
2014-03-10 16:49 1521#include <iostream> #i ... -
c++中的virtual inheritance
2014-01-27 10:20 800http://stackoverflow.com/questi ... -
Java的Generics和c++的Template到底有什么不同?
2012-12-27 16:21 3303先了解Java的Generics: 根据Java的文档,Jav ... -
Calculating Permutations and Job Interview Questions
2011-06-18 17:44 951http://www.bearcave.com/random_ ... -
字符串指针、字符数组的sizeof和strlen结果
2010-09-27 08:36 1460int main(){ char *p1=" ... -
code snippet
2010-09-27 08:31 925char temp[3]; char temp2[3]; ... -
虚继承
2010-09-26 09:03 960http://www.cppblog.com/franksun ... -
调整堆的算法
2010-09-25 10:34 1138Begin adjustHeap(A[], i) // He ... -
multiset usage as heap
2010-09-24 21:37 1444Middle number There is a seque ... -
虚函数表又是怎样实现的?
2010-09-20 22:01 1315每个含有虚函数的类 ... -
正整数分解算法
2010-09-19 16:56 4029问题:将以正整数n表 ... -
异或运算法则
2010-09-14 09:47 21911. a ^ b = b ^ a 2 ... -
常量字符串为什么位于静态存储区
2010-09-13 22:41 1254http://hi.baidu.com/%D0%C7%BB%F ... -
errno.h
2010-08-10 08:46 1513查看错误代码errno是调试程序的一个重要方法。当linuc ... -
How to use fallocate system call
2010-08-07 22:19 3426/* * fallocate - utility to u ... -
how to reverse the word sequence in a sentence?
2010-07-06 22:01 1227For example, "Welcome ... -
c++ dynamic binding
2010-07-06 21:20 896Good tutorial about c++ dynamic ... -
deep copy & shallow copy
2010-07-06 20:57 1119A 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 ...
Unlike languages like C or C++, where developers must manually manage memory, C# takes care of allocating and deallocating memory automatically. This simplifies development and reduces the risk of ...
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, ...
Based on the provided information from "iOS 5 Programming Cookbook" by Vandad Nahavandipoor, we can derive a comprehensive set of knowledge points related to iOS development using Objective-C....
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 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 ...
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 ...
- **Data Processing**: This involves the transformation of raw data into meaningful information through various steps such as input, processing, output, and storage. #### Programming Languages This ...
The job shop scheduling problem involves optimizing the sequence, timing, and allocation of tasks on various machines to minimize production time or cost while meeting specific constraints. ...
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 ...
这篇文章的标题为《通过数据包络分析(DEA)分配固定成本或资源并设定目标》,描述中重复了标题的内容。文章的关键词包括“数据包络分析”、“效率”、“固定成本分配”、“资源分配”和“目标设定”。...
The guide provides a detailed overview of the various components that make up a Linux system, including: - **Operating System Components**: The guide explains the different parts of an operating ...
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 ...
- **Dynamic Allocation of Arrays**: Explanation of allocating arrays dynamically using the `new` keyword and freeing them with `delete`. - **Operator Overloading**: Introduction to operator ...
It involves identifying and measuring the cost drivers of various activities and allocating indirect costs more accurately. **Relevance in IT**: ABC is highly relevant in IT because it helps in ...