Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Naohiro Aota <naohiro.aota@wdc.com>
To: fstests@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, Naohiro Aota <naohiro.aota@wdc.com>
Subject: [PATCH v3 0/3] use shuf to choose a random file
Date: Mon, 21 Aug 2023 16:12:10 +0900	[thread overview]
Message-ID: <cover.1692600259.git.naohiro.aota@wdc.com> (raw)

Currently, we use "ls ... | sort -R | head -n1" (or tail) to choose a
random file in a directory.It sorts the files with "ls", sort it randomly
and pick the first line, which wastes the "ls" sort.

Also, using "sort -R | head -n1" is inefficient. Furthermore, even without
"head" or "tail", "shuf" is faster than "sort -R".

This series introduces a new helper _random_file() to choose a file in a
directory randomly. Also, replace "sort -R" with _random_file() or "shuf".

Changes:
- v2
  - Introduce _random_file() helper
  - Rewrite other "sort -R" with _random_file() or "shuf"
- v3
  - Fix _random_file() helper to add the base directory as prefix

Naohiro Aota (3):
  common/rc: introduce _random_file() helper
  fstests/btrfs: use _random_file() helper
  btrfs/004: use shuf to shuffle the file lines

 common/rc       |  7 +++++++
 tests/btrfs/004 |  2 +-
 tests/btrfs/179 |  9 ++++-----
 tests/btrfs/192 | 14 ++++----------
 4 files changed, 16 insertions(+), 16 deletions(-)

-- 
2.41.0


             reply	other threads:[~2023-08-21  7:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21  7:12 Naohiro Aota [this message]
2023-08-21  7:12 ` [PATCH v3 1/3] common/rc: introduce _random_file() helper Naohiro Aota
2023-08-21  9:24   ` Anand Jain
2023-08-25 13:39   ` Zorro Lang
2023-08-25 14:00     ` Zorro Lang
2023-08-28  1:37       ` Naohiro Aota
2023-08-21  7:12 ` [PATCH v3 2/3] fstests/btrfs: use " Naohiro Aota
2023-08-21  9:25   ` Anand Jain
2023-08-21  7:12 ` [PATCH v3 3/3] btrfs/004: use shuf to shuffle the file lines Naohiro Aota
2023-08-21  9:25   ` Anand Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1692600259.git.naohiro.aota@wdc.com \
    --to=naohiro.aota@wdc.com \
    --cc=fstests@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox