Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F103590748
daxpy.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Mar 3, 05:19
Size
649 B
Mime Type
text/x-c
Expires
Wed, Mar 5, 05:19 (1 d, 8 h)
Engine
blob
Format
Raw Data
Handle
24620323
Attached To
R11821 phys-743-lecture
daxpy.cpp
View Options
#include <chrono>
#include <iostream>
#include <vector>
int main() {
unsigned int N = 1e8;
std::vector<double> a(N);
std::vector<double> b(N);
std::vector<double> c(N);
for (unsigned int i = 0; i < N; ++i) {
a[i] = 1.0 * i;
b[i] = 10.0 * i;
}
double alpha = rand() % 1000 / 1000.0;
auto t1 = std::chrono::high_resolution_clock::now();
for (unsigned int i = 0; i < N; ++i) {
c[i] = a[i] + alpha * b[i];
}
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms_double = t2 - t1;
std::cout <<"For loop ran in " <<ms_double.count() <<"ms" <<std::endl;
return 0;
}
Event Timeline
Log In to Comment