From owner-freebsd-questions@FreeBSD.ORG Fri Feb 20 20:36:11 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9DB961065680 for ; Fri, 20 Feb 2009 20:36:11 +0000 (UTC) (envelope-from junsukshin@gmail.com) Received: from mail-gx0-f176.google.com (mail-gx0-f176.google.com [209.85.217.176]) by mx1.freebsd.org (Postfix) with ESMTP id 5A6EC8FC21 for ; Fri, 20 Feb 2009 20:36:11 +0000 (UTC) (envelope-from junsukshin@gmail.com) Received: by gxk24 with SMTP id 24so3740254gxk.19 for ; Fri, 20 Feb 2009 12:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=1wInbQ2gth44XXNLyju1UvKrqL9kN+o5PdLqe5fGfuQ=; b=X9fPz+YalNUiov5Fct89TP5zIrJUMHiHm4k+vcpkswGK2/5ZMpwLOakeK/3cbrLH66 fyazgdjd9UbnNoMzHtqDSlr5c4BFb2h5LfWDyKPbzprDAikDI1p2oDzQfVZkMXqjNQ6C IZw5Y+pG6am+fGp6X1GR0rfd2q9/fxaTEIt8E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=WmAvyACt0NJfjFe+cOMVpZzPoLUHQQcW++FDCu4Zz4dBhIn14B3AcsRUl2DgKZVwy7 BlD78+zndYrcg+btalikKstugEghb7IPPqR3YqofrAa3YTvWPuMZnPrA8E+FtUVMvybI rKqwTQgKtFkxIbP4J7DRYOrfE4WgvURnkD07Q= MIME-Version: 1.0 Received: by 10.231.16.129 with SMTP id o1mr1415213iba.47.1235160477893; Fri, 20 Feb 2009 12:07:57 -0800 (PST) Date: Fri, 20 Feb 2009 15:07:57 -0500 Message-ID: <7873ac110902201207t61038469o6a94d81bcd392941@mail.gmail.com> From: Junsuk Shin To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: read() vs fread() X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Feb 2009 20:36:11 -0000 Hi BSD guys, While I was doing simple file read test, I found that there is a huge difference in file read performance between read() and fread(). I'm wondering if I'm doing something wrong or if someone has experienced similar things. Here is what I did, For the specific application, I need to bypass cache (I read only once, and that's all) The test file is 700Mbytes dummy file. Test app just reads the whole file. Test is done on FreeBSD 7.1 amd 64, Celeron E1200, WD Caviar SE16 SATA 7200 RPM For test 1, fd = open(name, O_RDONLY | O_DIRECT); while(...) { cnt = read(....); .... } for test 2, fd = open(name, O_RDONLY | O_DIRECT); file = fdopen(fd,"r"); while(...) { cnt = fread(....); .... } test 1 takes about 11.64 seconds (63 MBytes/s), and test 2 takes about 51.53 seconds (14 MBytes/s) If I use the pair of fopen() and fread(), it will have cache effect, so the result doesn't say much of hdd performance. Personally, I don't think the overhead of fread() (wrapper in libc) is that huge. What would be the reason for this? Thanks. -- Junsuk