Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Why the speed of reading data from ramdisk is the same as harddisk?

Reply
Thread Tools

Why the speed of reading data from ramdisk is the same as harddisk?

 
 
sonet
Guest
Posts: n/a
 
      06-09-2006
/dev/sda2 49594228 1373972 45660300 3% /usr/local
/dev/ram0 96828 11976 84852 13%
/usr/local/Portal/cache

/usr/local/Portal/tesing (real filesystem)
/usr/local/Portal/cache/testing (ramdisk)

The file size is about 6M.

#--------------------------result-------------------------------
open file on ramdisk:6.60419464111328e-05
write file on ramdisk:0.0180449485778809
close file on ramdisk:4.10079956054688e-05
read data on ramdisk:0.179691076278687
=====================================
open file on disk:0.000105142593383789
write file on disk:0.0202229022979736
close file on disk:4.41074371337891e-05
read data on disk:0.0468909740447998

#---------------------------code--------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes();

my $t1=Time::HiRes::gettimeofday;
open(my $HH,">/usr/local/Portal/cache/testing");
print "open file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";

my $str='';
for (my $i=0;$i<=1000000;$i++){
$str.=$i;
}
$t1=Time::HiRes::gettimeofday;
print $HH $str;
print "write file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
close($HH);
print "close file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
open($HH,"/usr/local/Portal/cache/testing");
my $a=join('',<$HH>);
close($HH);
print "read data on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$a='';
$t1=Time::HiRes::gettimeofday;

print "=====================================\n";

open($HH,">/usr/local/Portal/testing");
print "open file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$str='';
for (my $i=0;$i<=1000000;$i++){
$str.=$i;
}
$t1=Time::HiRes::gettimeofday;
print $HH $str;
print "write file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
close($HH);
print "close file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
open($HH,"/usr/local/Portal/testing");
$a=join('',<$HH>);
close($HH);
print "read data on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$a='';



 
Reply With Quote
 
 
 
 
sonet
Guest
Posts: n/a
 
      06-09-2006
/dev/sda2 49594228 1373972 45660300 3% /usr/local
/dev/ram0 96828 11976 84852 13%
/usr/local/Portal/cache

/usr/local/Portal/tesing (real filesystem)
/usr/local/Portal/cache/testing (ramdisk)

The file size is about 6M.

#--------------------------result-------------------------------
open file on ramdisk:6.38961791992188e-05
write file on ramdisk:0.0180280208587646
close file on ramdisk:3.91006469726562e-05
read data on ramdisk:0.178893089294434
=====================================
open file on disk:0.000104904174804688
write file on disk:0.0201010704040527
close file on disk:4.50611114501953e-05
read data on disk:0.0465281009674072

#---------------------------code--------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes();

my $t1=Time::HiRes::gettimeofday;
open(my $HH,">/usr/local/Portal/cache/testing");
print "open file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";

my $str='';
for (my $i=0;$i<=1000000;$i++){
$str.=$i;
}
$t1=Time::HiRes::gettimeofday;
print $HH $str;
print "write file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
close($HH);
print "close file on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
open($HH,"/usr/local/Portal/cache/testing");
my $a=join('',<$HH>);
close($HH);
print "read data on ramdisk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$a='';
print "=====================================\n";
$t1=Time::HiRes::gettimeofday;
open($HH,">/usr/local/Portal/testing");
print "open file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$str='';
for (my $i=0;$i<=1000000;$i++){
$str.=$i;
}
$t1=Time::HiRes::gettimeofday;
print $HH $str;
print "write file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
close($HH);
print "close file on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$t1=Time::HiRes::gettimeofday;
open($HH,"/usr/local/Portal/testing");
$a=join('',<$HH>);
close($HH);
print "read data on disk:" . (Time::HiRes::gettimeofday -$t1) . "\n";
$a='';





 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      06-09-2006
sonet schreef:

> Subject: Why the speed of reading data from ramdisk is the same as

harddisk?

Why not? There is easily more than 1 RAM-buffer involved: many harddisks
have 8 MB RAM aboard, and the OS reads large chunks from the harddisk at
a time, even if you ask only for a single byte.

About writing: many harddisks report 'OK' when the data is available, so
long before the data is physically written to 'the platters'.

--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Ramdisk for x64 =?Utf-8?B?Sm9hY2hpbQ==?= Windows 64bit 6 08-05-2005 08:18 AM
DBI DBM Slow - Is a ramdisk the answer? burlo.stumproot@gmail.com Perl Misc 7 03-16-2005 10:52 PM
Some RAMdisk solution? Oliver C++ 1 10-30-2003 10:27 AM
running windows NT on a ramdisk tim NZ Computing 7 08-29-2003 08:47 AM



Advertisments