Sourceware Bugzilla – Attachment 7191 Details for
Bug 15936
Computing sin and cos is very slow when using AVX-powered processors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
C program showing an slow behavior of sin/cos
bug-avx.c (text/x-csrc), 1.62 KB, created by
Francesc Alted
on 2013-09-06 09:53:01 UTC
(
hide
)
Description:
C program showing an slow behavior of sin/cos
Filename:
MIME Type:
Creator:
Francesc Alted
Created:
2013-09-06 09:53:01 UTC
Size:
1.62 KB
patch
obsolete
>/* ####################################################################### */ >/* This script compares the speed of the computation of a polynomial */ >/* in C in a couple of different ways. */ >/* */ >/* Author: Francesc Alted */ >/* Date: 2013-09-04 */ >/* ####################################################################### */ > > >#include <stdio.h> >#include <math.h> >#include <unistd.h> >#include <sys/time.h> >#include <fenv.h> >#include <time.h> >#include <string.h> > >#define N 10*1000*1000 > >double x[N]; >double y[N]; > >/* Given two timeval stamps, return the difference in seconds */ >float getseconds(struct timeval last, struct timeval current) { > int sec, usec; > > sec = current.tv_sec - last.tv_sec; > usec = current.tv_usec - last.tv_usec; > return (float)(((double)sec + usec*1e-6)); >} > >int main(void) { > long i; > double inf_ = 0; > double dN = 2./N; > struct timeval last, current; > float tspend; > > /* Initialize array */ > for(i=0; i<N; i++) { > x[i] = inf_ + i*dN; > } > > /* Commit the y vector (just to be fair with the Python counterparts) */ > memset(y, 0, sizeof(y)); > > /* Perform actual computation */ > printf("Starting computation...\n"); > gettimeofday(&last, NULL); > for(i=0; i<N; i++) { > double t_c = cos(x[i]); > double t_s = sin(x[i]); > y[i] = t_s * t_s + t_c * t_c; > } > gettimeofday(¤t, NULL); > tspend = getseconds(last, current); > printf("Compute time:\t %.3f s\n", tspend); > > return(0); >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 15936
: 7191