Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
queues
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
samarth5
queues
Commits
818aa561
Commit
818aa561
authored
7 years ago
by
samarth5
Browse files
Options
Downloads
Patches
Plain Diff
Adding gitignore; Making benchmarking code more generic
parent
f9fa33da
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+3
-0
3 additions, 0 deletions
.gitignore
BenchmarkingModule.cpp
+28
-13
28 additions, 13 deletions
BenchmarkingModule.cpp
with
31 additions
and
13 deletions
.gitignore
0 → 100644
+
3
−
0
View file @
818aa561
*.o
*.csv
BenchmarkingModule
\ No newline at end of file
This diff is collapsed.
Click to expand it.
BenchmarkingModule.cpp
+
28
−
13
View file @
818aa561
...
@@ -4,31 +4,36 @@
...
@@ -4,31 +4,36 @@
#include
<numeric>
#include
<numeric>
#include
<thread>
#include
<thread>
#include
<assert.h>
#include
<assert.h>
#include
<cxxabi.h>
using
namespace
std
;
using
namespace
std
;
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
#define quote(x) #x
const
int
NumberToEnqueue
=
2
;
template
<
class
T
>
template
<
class
T
>
void
EnqueueNItems
(
IQueue
<
T
>
&
queue
,
int
n
)
void
EnqueueNItems
(
IQueue
<
T
>
&
queue
,
int
n
)
{
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
{
queue
.
enqueue
(
2
);
queue
.
enqueue
(
NumberToEnqueue
);
}
}
}
}
double
CreateNThreadsAndPerformKOperations
(
int
n
,
int
k
)
template
<
class
T
>
void
CreateNThreadsAndPerformKOperations
(
string
operatioName
,
void
(
*
OperationToPerform
)(
IQueue
<
T
>
&
queueInstance
,
int
numberOfRepititions
),
IQueue
<
T
>
*
baseQueuePointer
,
int
n
,
int
k
)
{
{
IQueue
<
T
>
&
baseQueue
=
*
baseQueuePointer
;
thread
workers
[
n
];
thread
workers
[
n
];
LockQueue
<
int
>
lockedQueue
;
auto
start
=
high_resolution_clock
::
now
();
auto
start
=
high_resolution_clock
::
now
();
// do some work
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
{
workers
[
i
]
=
thread
(
EnqueueNItems
<
int
>
,
ref
(
locked
Queue
),
k
);
workers
[
i
]
=
thread
(
OperationToPerform
,
ref
(
base
Queue
),
k
);
}
}
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
...
@@ -37,15 +42,25 @@ double CreateNThreadsAndPerformKOperations(int n, int k)
...
@@ -37,15 +42,25 @@ double CreateNThreadsAndPerformKOperations(int n, int k)
}
}
auto
end
=
high_resolution_clock
::
now
();
auto
end
=
high_resolution_clock
::
now
();
duration
<
double
>
diff
=
end
-
start
;
assert
(
lockedQueue
.
size
()
==
n
*
k
);
assert
(
baseQueue
.
size
()
==
n
*
k
);
duration
<
double
>
diff
=
end
-
start
;
int
status
;
return
diff
.
count
();
char
*
demangledName
=
abi
::
__cxa_demangle
(
typeid
(
baseQueue
).
name
(),
0
,
0
,
&
status
);
printf
(
"%s,%s,%f,%d,%d
\n
"
,
demangledName
,
operatioName
.
c_str
(),
diff
.
count
(),
n
,
k
);
}
}
// 1. Try with different types of objects (ints, classes) to see if that affects the performance.
// 2. Try only enqueue operations.
// 3. Try enqueue and dequeue operations together.
int
main
()
int
main
()
{
{
cout
<<
CreateNThreadsAndPerformKOperations
(
100
,
1000
)
<<
endl
;
cout
<<
"Queue,OperationName,TimeTakenToExecute,NumberOfThreads,NumberOfOperations"
<<
endl
;
cout
<<
CreateNThreadsAndPerformKOperations
(
100
,
100000
)
<<
endl
;
CreateNThreadsAndPerformKOperations
(
quote
(
EnqueueNItems
),
EnqueueNItems
,
new
LockQueue
<
int
>
(),
100
,
1000
);
CreateNThreadsAndPerformKOperations
(
quote
(
EnqueueNItems
),
EnqueueNItems
,
new
LockQueue
<
int
>
(),
100
,
100000
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment