From: "Arcady V. Ivanov" <arc@help0.ru>
To: ALT Linux Sisyphus discussion list <sisyphus@lists.altlinux.org>
Subject: Re: [sisyphus] Скорость программы...
Date: Thu, 01 Mar 2007 22:19:03 +1200
Message-ID: <45E6A897.9050409@help0.ru> (raw)
In-Reply-To: <200703011259.13606.serpiph@nikiet.ru>
Epiphanov Sergei пишет:
> Не понимаю, почему программа вида:
> ===================
> int main(void)
> {
> float N[30*60*60];
> int i,j,k,shift;
> for (i=0; i<30;i++)
> for(j=0;j<60;j++)
> for(k=0;k<60;k++){
> shift=i*60*60+j*60+k;
> N[shift]=<расчёт>;
> }
> }
> ===================
> работает на порядки быстрее программы
> ===================
> int main(void)
> {
> float N[30*60*60];
> int i,j,k,shift;
> shift=0;
> for (i=0; i<30;i++)
> for(j=0;j<60;j++)
> for(k=0;k<60;k++){
> shift++;
> N[shift]=<расчёт>;
> }
> }
> ===================
> Хотя, теоретически, должно быть наоборот. Расчёт в обоих случаях один и тот
> же. gcc-4.1.1.alt11. Сборка программы с параметром -O2 (-Os то же самое).
>
> Может кто подсказать?
>
Автоматические переменные выделяются в стеке, т.е. массив N откусывается
в стеке. Он примерно с мегабайт.
Попробуйте сделать N static и проверьте скорость.
Если будет одинакова, значит есть какой-то механизм увеличения стека по
исключениям обращения к памяти, что довольно занудно.
Но это догадки.
--
С уважением. Иванов Аркадий
Зам.директора ООО "Хелп"
mailto: arc@help0.ru
web:http://www.help0.ru
mobile: 8-962-290-8343
------------------------------------
I use stable soft:
Linux, Mozilla and OpenOffice.
And recommend them for you too.
next prev parent reply other threads:[~2007-03-01 10:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-01 9:59 Epiphanov Sergei
2007-03-01 10:19 ` Arcady V. Ivanov [this message]
2007-03-01 10:20 ` Damir Shayhutdinov
2007-03-01 10:37 ` Epiphanov Sergei
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=45E6A897.9050409@help0.ru \
--to=arc@help0.ru \
--cc=sisyphus@lists.altlinux.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
ALT Linux Sisyphus discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
public-inbox-index sisyphus
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.sisyphus
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git