mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-29 06:12:18 -06:00
InVectorCache
git-svn-id: svn://ultimatepp.org/upp/trunk@5852 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
99fb4b9230
commit
d9754cdda3
3 changed files with 68 additions and 0 deletions
55
benchmarks/InVectorCache/InVectorCache.cpp
Normal file
55
benchmarks/InVectorCache/InVectorCache.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
int N = 10;
|
||||
InVector<int> x;
|
||||
for(int i = 0; i < 1000000; i++)
|
||||
x.Add(Random(1000));
|
||||
{
|
||||
RTIMING("Simple scan");
|
||||
int m = 0;
|
||||
for(int j = 0; j < N; j++) {
|
||||
for(int i = 0; i < x.GetCount(); i++)
|
||||
m += x[i];
|
||||
for(int i = x.GetCount(); --i >= 0;)
|
||||
m += x[i];
|
||||
}
|
||||
RDUMP(m);
|
||||
}
|
||||
{
|
||||
RTIMING("Single InVector, problematic scan");
|
||||
int m = 0;
|
||||
for(int j = 0; j < N; j++) {
|
||||
for(int i = 0; i < x.GetCount(); i++)
|
||||
m += x[i] + x[x.GetCount() - i - 1];
|
||||
}
|
||||
RDUMP(m);
|
||||
}
|
||||
{
|
||||
InVector<int> y;
|
||||
y <<= x;
|
||||
RTIMING("Two InVectors");
|
||||
int m = 0;
|
||||
for(int j = 0; j < N; j++) {
|
||||
for(int i = 0; i < x.GetCount(); i++)
|
||||
m += x[i] + y[i];
|
||||
}
|
||||
RDUMP(m);
|
||||
}
|
||||
{
|
||||
InVector<int> y;
|
||||
y <<= x;
|
||||
RTIMING("Two InVectors, two simple scans");
|
||||
int m = 0;
|
||||
for(int j = 0; j < N; j++) {
|
||||
for(int i = 0; i < x.GetCount(); i++)
|
||||
m += x[i];
|
||||
for(int i = y.GetCount(); --i >= 0;)
|
||||
m += y[i];
|
||||
}
|
||||
RDUMP(m);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue