From: Lars-Peter Clausen <lars@metafoo.de>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
Stefan Popa <stefan.popa@analog.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Hartmut Knaack <knaack.h@gmx.de>,
Peter Meerwald <pmeerw@pmeerw.net>,
linux-iio <linux-iio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/5] iio:adxl372: Add sampling frequency support
Date: Thu, 12 Jul 2018 20:31:59 +0200 [thread overview]
Message-ID: <4bfc67b7-b062-a8cb-8a30-ccd117d67db9@metafoo.de> (raw)
In-Reply-To: <CAHp75Ve+S7UDyLva_PY4s=cjKoSY+aMfWDUEHb6tp4AxGtGsDg@mail.gmail.com>
On 07/12/2018 08:25 PM, Andy Shevchenko wrote:
> On Thu, Jul 12, 2018 at 6:36 PM, Stefan Popa <stefan.popa@analog.com> wrote:
>> This patch adds the option for the user to select the sampling frequency.
>> Also, the user can read the available frequencies and read the currently
>> set frequency via the read_raw function. The frequency can be set via the
>> write_raw function.
>>
>> When the frequency is set, the bandwidth is also checked and ensured
>> that it is constrained to at most half of the sampling frequency.
>
>> +static int adxl372_find_closest_match(const int *array,
>> + unsigned int size, int val)
>> +{
>> + int i;
>> +
>> + for (i = 0; i < size; i++) {
>> + if (val <= array[i])
>> + return i;
>> + }
>> +
>> + return size - 1;
>> +}
>
> Perhaps it's time to extend bsearch with something called
> bsearch_closest().
>
While it makes sense to have a helper function for this the generic bsearch
is not a good solution for small arrays. The generated code is probably
larger and the function call overhead of calling the cmp function completely
outweighs the savings from doing a binary search. bsearch() is good if your
array has 100s or 1000s of entries. If it only has 5, not so much.
prev parent reply other threads:[~2018-07-12 18:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-12 15:36 Stefan Popa
2018-07-12 18:25 ` Andy Shevchenko
2018-07-12 18:31 ` Lars-Peter Clausen [this message]
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=4bfc67b7-b062-a8cb-8a30-ccd117d67db9@metafoo.de \
--to=lars@metafoo.de \
--cc=Michael.Hennerich@analog.com \
--cc=andy.shevchenko@gmail.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=stefan.popa@analog.com \
/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
all inboxes | Powered by JetHome®