Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COMP290 Benchmarking Examples
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Falmouth Computing
Example Solutions
COMP290 Benchmarking Examples
Commits
3f347d26
Commit
3f347d26
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
removing the erase hotspot from the vector
parent
1c72e219
Branches
jwr-solutions
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
labs/counting/main.cpp
+6
-4
6 additions, 4 deletions
labs/counting/main.cpp
with
6 additions
and
4 deletions
labs/counting/main.cpp
+
6
−
4
View file @
3f347d26
...
...
@@ -25,6 +25,8 @@ std::vector<int> readNumbers(const char* filename) {
// read the numbers in (first line = number of inputs)
std
::
fscanf
(
fp
,
"%d"
,
&
nCount
);
numbers
.
reserve
(
nCount
);
for
(
int
i
=
0
;
i
<
nCount
;
++
i
)
{
int
nextNum
=
0
;
std
::
fscanf
(
fp
,
"%d"
,
&
nextNum
);
...
...
@@ -40,13 +42,13 @@ std::vector<int> readNumbers(const char* filename) {
* @param numbers the numbers to calculate
* @return the average of the input values
*/
float
calcAverage
(
std
::
vector
<
int
>
numbers
)
{
float
calcAverage
(
std
::
vector
<
int
>
&
numbers
)
{
int
total
=
0
;
int
size
=
0
;
while
(
!
numbers
.
empty
()
)
{
total
+=
numbers
[
0
]
;
numbers
.
erase
(
numbers
.
begin
()
);
total
+=
numbers
.
back
()
;
numbers
.
pop_back
(
);
size
++
;
}
...
...
@@ -84,7 +86,7 @@ int main(int argc, const char* argv[]) {
}
// calculate and print the average
auto
avg
=
calcAverage
Fast
(
numbers
);
auto
avg
=
calcAverage
(
numbers
);
std
::
cout
<<
"the average is: "
<<
avg
<<
std
::
endl
;
return
EXIT_SUCCESS
;
...
...
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