Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Which is more expensive Rename or Move?

Reply
Thread Tools

Which is more expensive Rename or Move?

 
 
Mrmaster Mrmaster
Guest
Posts: n/a
 
      06-16-2009
Hello,

I'd like to create a ruby script that parses emails(that will grow with
volume) and I need to find a way to distinct which emails the script
touches. I can either rename the email after the script is done with it
or move it to another directory. Which would be a least costly operation
or are they both equal expensive?

Would you have any other suggestions for this problem?

The way I understand it is that when you rename or change directory you
are just changing the path. I will be using a linux box(ubuntu) and I
think the directories are stored in a tree structure in which rename
would be less expensive.

Thank you
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Kyle Schmitt
Guest
Posts: n/a
 
      06-16-2009
Assuming it's on the same filesystem, and you're using a real
filesystem format (ext2/3, xfs, jfs, etc), they should be almost
identical....

According to the docs on the File class though, it uses syscopy for
move, which seems odd to me, but the performance should be almost
identical.

--Kyle

 
Reply With Quote
 
 
 
 
Mrmaster Mrmaster
Guest
Posts: n/a
 
      06-16-2009
Kyle Schmitt wrote:
> Assuming it's on the same filesystem, and you're using a real
> filesystem format (ext2/3, xfs, jfs, etc), they should be almost
> identical....
>
> According to the docs on the File class though, it uses syscopy for
> move, which seems odd to me, but the performance should be almost
> identical.
>
> --Kyle


Hi Kyle,

I'm using ext filesystem. Why would they operations be identical? I
thought the directories are stored in a tree structure so wouldn't it
require another n(logn) operation to find a new directory during a move?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Kyle Schmitt
Guest
Posts: n/a
 
      06-16-2009
Because moving and renaming files consist of the same operations.

To really really overly simplify it, moving a directory primarily
involves updating the directory, not every node under it.

I'm a bit busy to lookup papers on how it works, but do some googling
for how filesystems work.

 
Reply With Quote
 
Mrmaster Mrmaster
Guest
Posts: n/a
 
      06-16-2009
Kyle Schmitt wrote:
> Because moving and renaming files consist of the same operations.
>
> To really really overly simplify it, moving a directory primarily
> involves updating the directory, not every node under it.
>
> I'm a bit busy to lookup papers on how it works, but do some googling
> for how filesystems work.


Thanks, I'll do the research. I just neded to know of the costs
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Phil Romero
Guest
Posts: n/a
 
      06-17-2009
On Tue, Jun 16, 2009 at 11:45 AM, Mrmaster
Mrmaster<(E-Mail Removed)> wrote:
> Kyle Schmitt wrote:
>> Because moving and renaming files consist of the same operations.
>>
>> To really really overly simplify it, moving a directory primarily
>> involves updating the directory, not every node under it.
>>
>> I'm a bit busy to lookup papers on how it works, but do some googling
>> for how filesystems work.

>
> Thanks, I'll do the research. I just neded to know of the costs
> --
> Posted via http://www.ruby-forum.com/.
>
>


Just to add a bit more to this conversation, the only time an mv
operation would be more expensive is in the case of actually mv'ing
across filesystems. You could have mv'd a file from say your
/home/username directory on sda1 to /newhome/username on sda2 (two
physically different partitions). Strange that this would come up. I
think rename is mv with a cross filesystem limitation. I don't use
rename for anything in *nix, always has been mv.

 
Reply With Quote
 
Mrmaster Mrmaster
Guest
Posts: n/a
 
      06-17-2009
Phil Romero wrote:
> On Tue, Jun 16, 2009 at 11:45 AM, Mrmaster
> Mrmaster<(E-Mail Removed)> wrote:
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>>

>
> Just to add a bit more to this conversation, the only time an mv
> operation would be more expensive is in the case of actually mv'ing
> across filesystems. You could have mv'd a file from say your
> /home/username directory on sda1 to /newhome/username on sda2 (two
> physically different partitions). Strange that this would come up. I
> think rename is mv with a cross filesystem limitation. I don't use
> rename for anything in *nix, always has been mv.


I think the rename command in the linux box calls a perl script too
which will add to the cost.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      06-17-2009
On 17.06.2009 02:56, Mrmaster Mrmaster wrote:
> Phil Romero wrote:
>> On Tue, Jun 16, 2009 at 11:45 AM, Mrmaster
>> Mrmaster<(E-Mail Removed)> wrote:


> I think the rename command in the linux box calls a perl script too
> which will add to the cost.


There is rename functionality in Ruby's standard library. Why bother to
call some external command for this?

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Matthew K. Williams
Guest
Posts: n/a
 
      06-17-2009
On Wed, 17 Jun 2009, Phil Romero wrote:

> Just to add a bit more to this conversation, the only time an mv
> operation would be more expensive is in the case of actually mv'ing
> across filesystems. You could have mv'd a file from say your
> /home/username directory on sda1 to /newhome/username on sda2 (two
> physically different partitions). Strange that this would come up. I
> think rename is mv with a cross filesystem limitation. I don't use
> rename for anything in *nix, always has been mv.
>


Historically (~15-20 years ago and prior) you couldn't do a mv across
filesystems; at that time mv only changed the inode tables, it didn't do
any copying of data. I think the first I ran into a mv which would work
across filesystems was in the mid to late 90's.

Matt

 
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
Which operation is more expensive?(a <= b and a != 0) Ping Cheu C Programming 28 03-14-2012 05:07 AM
Which operation is more expensive?(a <= b and a != 0) zaemin C Programming 5 06-04-2005 07:15 PM
Standalone camera which upload pictures on button press ? Not too expensive... Martin Maurer Digital Photography 2 02-28-2005 01:15 AM
printer for digital photos- which are very good- and not too expensive KOS Digital Photography 9 05-14-2004 05:03 AM
Which company makes the best 550W power supply? I want the Enermax EG651P-VE but it's soooo expensive (for a PSU, that is). Obsessed Tech A+ Certification 1 12-30-2003 02:51 PM



Advertisments