To keep failing requires that I fail multiple times which is not the case. Besides, I don't see you trying to take them.Jason wrote:maybe that's why he keeps failing his PhD qualifier.Dwindlehop wrote:you don't have any left?quantus wrote:courses? what are those?
Peijen's Programming Thread 1.0
-
- Grand Pooh-Bah
- Posts: 6722
- Joined: Tue Sep 19, 2006 8:45 pm
- Location: Portland, OR
- Contact:
Did you ever write anything like this?Peijen wrote:he did outline what you need to do. If you want to wait I will code it up next week, and I will send you a copy since I will need to use it too.Dwindlehop wrote:Fuck that noise. There is no testNumEq in numeric_limits. As far as I can tell, the code listing only exists in the print version of that article and isn't available online.
Or you can code it up and send me a copy.
-
- Minion to the Exalted Pooh-Bah
- Posts: 2790
- Joined: Fri Jul 18, 2003 2:28 pm
- Location: Irvine, CA
hehe, too bad it's not intern season.quantus wrote:heh, don't get too attached to this project either. Chances are they'll tell you to put this one on hold for something else. Iterate 'til you have infinite projects and nothing finished.
The only chance you have of finishing anything is if you get an intern
-
- Tenth Dan Procrastinator
- Posts: 3055
- Joined: Fri Jul 18, 2003 3:02 am
- Location: Varies
- Contact:
Don't know if it should go in this thread, but why not.
You can pass functions as parameters in C++ !!!
example:
http://www.csm.astate.edu/~rossa/cs3543/fparm.html
I was thinking about using this for a timing wrapper (evaluates how long an arbitrary method takes). However, since it requires explicitly stating the method signature, and the methods I'm evaluating have different signatures, I'm SOL (shit out of luck).
Sigh, time for repetitive code I guess.
You can pass functions as parameters in C++ !!!
example:
http://www.csm.astate.edu/~rossa/cs3543/fparm.html
I was thinking about using this for a timing wrapper (evaluates how long an arbitrary method takes). However, since it requires explicitly stating the method signature, and the methods I'm evaluating have different signatures, I'm SOL (shit out of luck).
Sigh, time for repetitive code I guess.
-
- Tenth Dan Procrastinator
- Posts: 3055
- Joined: Fri Jul 18, 2003 3:02 am
- Location: Varies
- Contact:
Timing Fun
Okay, I'm missing something basic here. For some reason, the duration is exactly 0, and I definitely notice the sleep delay.
Note1: sleeptime_variable() is to test passing a method with a different signature in the future.
Note2: not sure the CLOCKS_PER_SEC is set correctly
funct_passing.cpp:
Here's the output:
Note1: sleeptime_variable() is to test passing a method with a different signature in the future.
Note2: not sure the CLOCKS_PER_SEC is set correctly
funct_passing.cpp:
Code: Select all
#include <stdio.h>
void sleeptime() {
printf(" sleeptime(): start\n");
sleep(5);
printf(" sleeptime(): done!\n");
}
void sleeptime_variable(int i) {
printf(" sleeptime_variable(%d): start\n");
sleep(i);
printf(" sleeptime_variable(%d): done!\n");
}
void timer2(void f()) {
printf("\ntimer2(): start\n");
clock_t start = clock();
f();
printf("timer2(): done! (%lf ms)\n",
(clock() - start)/(CLOCKS_PER_SEC / (double) 1000.0));
}
void timer(void f()) {
printf("\ntimer(): start\n");
clock_t start = clock();
f();
clock_t end = clock();
printf("timer(): done! (%lf ms)\nNote: ", end-start);
if (start == end) {
printf("start == end\n");
} else {
printf("start != end\n");
}
}
void main() {
timer(sleeptime);
timer2(sleeptime);
}
Code: Select all
timer(): start
sleeptime(): start
sleeptime(): done!
timer(): done! (0.000000 ms)
Note: start == end
timer2(): start
sleeptime(): start
sleeptime(): done!
timer2(): done! (0.000000 ms)
Last edited by VLSmooth on Wed Oct 22, 2003 11:29 pm, edited 1 time in total.
-
- Tenth Dan Procrastinator
- Posts: 3055
- Joined: Fri Jul 18, 2003 3:02 am
- Location: Varies
- Contact:
On the other hand, this works: (I wrote this earlier for fun). This explains why I'm confused about funct_passing.cpp above. Note that I use a very similar timing method above (just changed the signature), in addition to a new one that differs by a start,end comparison.
vector_speed.cpp:
Here's the output:
vector_speed.cpp:
Code: Select all
#include <stdio.h>
// this is a wrapper that takes in a method
// note: the method's signature must be completely specified
// in the wrapper's signature
void timer(vector<int> v, void print_method(vector<int>)) {
clock_t start = clock();
print_method(v);
printf("time: %lf ms\n",
(clock() - start)/(CLOCKS_PER_SEC / (double) 1000.0));
}
void print_vector_slow(vector<int> v) {
for(int i=0;i<v.size();i++) {
// printf(" %d", v[i]);
}
printf("\ndone! (print_vector_slow)\n");
}
void print_vector_medium(vector<int> v) {
vector<int>::iterator v_iter = v.begin();
while(v_iter != v.end()) {
// printf(" %d", *(v_iter++));
v_iter++;
}
printf("\ndone! (print_vector_medium)\n");
}
void print_vector_fast(vector<int> v) {
vector<int>::iterator v_iter = v.begin();
int * v_end = v.end();
while(v_iter != v_end) {
// printf(" %d", *(v_iter++));
v_iter++;
}
printf("\ndone! (print_vector_fast)\n");
}
void main() {
vector<int> v_x;
int i = 0; while (i<5000000) { v_x.push_back(i++); }
timer(v_x,print_vector_slow);
timer(v_x,print_vector_medium);
timer(v_x,print_vector_fast);
}
Code: Select all
done! (print_vector_slow)
time: 380.000000 ms
done! (print_vector_medium)
time: 150.000000 ms
done! (print_vector_fast)
time: 110.000000 ms
-
- Grand Pooh-Bah
- Posts: 6722
- Joined: Tue Sep 19, 2006 8:45 pm
- Location: Portland, OR
- Contact:
Code: Select all
struct {
int A;
int B;
double C;
} arg1_t;
struct {
char X;
char Y;
} arg2_t;
void fn1(void * args) {
dostuff((arg1_t*)args);
}
void fn2(void * args) {
dodifferentthings((arg2_t*)args);
}
void callmyfunction(void genericfn(void * args), void * thisargs, SomeType otherarg) {
calculatestuff(otherarg);
genericfn(thisargs);
}
int main() {
arg1_t *penis = initialize();
callmyfunction(fn1, (void *)penis, iamtirednow)
return LOVE_FOR_VINNY;
}