Which is more expensive Rename or Move?

Discussion in 'Ruby' started by Mrmaster Mrmaster, Jun 16, 2009.

  1. 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/.
     
    Mrmaster Mrmaster, Jun 16, 2009
    #1
    1. Advertising

  2. Mrmaster Mrmaster

    Kyle Schmitt Guest

    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
     
    Kyle Schmitt, Jun 16, 2009
    #2
    1. Advertising

  3. 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/.
     
    Mrmaster Mrmaster, Jun 16, 2009
    #3
  4. Mrmaster Mrmaster

    Kyle Schmitt Guest

    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.
     
    Kyle Schmitt, Jun 16, 2009
    #4
  5. 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/.
     
    Mrmaster Mrmaster, Jun 16, 2009
    #5
  6. Mrmaster Mrmaster

    Phil Romero Guest

    On Tue, Jun 16, 2009 at 11:45 AM, Mrmaster
    Mrmaster<> 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.
     
    Phil Romero, Jun 17, 2009
    #6
  7. Phil Romero wrote:
    > On Tue, Jun 16, 2009 at 11:45 AM, Mrmaster
    > Mrmaster<> 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/.
     
    Mrmaster Mrmaster, Jun 17, 2009
    #7
  8. On 17.06.2009 02:56, Mrmaster Mrmaster wrote:
    > Phil Romero wrote:
    >> On Tue, Jun 16, 2009 at 11:45 AM, Mrmaster
    >> Mrmaster<> 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/
     
    Robert Klemme, Jun 17, 2009
    #8
  9. 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
     
    Matthew K. Williams, Jun 17, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zaemin
    Replies:
    5
    Views:
    417
    Denis Bueno
    Jun 4, 2005
  2. shapper

    Rename and Move File

    shapper, Feb 12, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    423
    Misbah Arefin
    Feb 12, 2008
  3. cliffyg
    Replies:
    0
    Views:
    472
    cliffyg
    Mar 6, 2008
  4. Ping Cheu
    Replies:
    28
    Views:
    737
    Barry Schwarz
    Mar 14, 2012
  5. kwalike57
    Replies:
    6
    Views:
    266
    Tad J McClellan
    Jan 10, 2008
Loading...

Share This Page