Performance penalty for using classes?
André Jonsson
tatsujin at despammed.com
Wed Jan 15 13:57:43 EST 2003
Seems to me that the C program is almost 10 times faster...
Miki Tebeka wrote:
> Hello All,
>
> Thanks for your help.
> Looks like the winning combination will be struct + psyco + 2.3 which
> <AMAZING> runs faster than the c test (compiled with -O3) </AMAZING>
>
> [09:37] $time ./struct_test_psyco.py
> Going 100000 iterations
> * Done
> real 0.25
> user 0.25
> sys 0.00
> [09:37] $time ./c_t
> c_test c_test.c
> [09:37] $time ./c_test
> Going 1000000 iterations
> * Done
> real 0.34
> user 0.29
> sys 0.04
>
> Miki
>
> --- c_test.c ---
*snip*
> int
> main(int argc, char *argv[])
> {
> long iterations = 1000000;
> if (argc > 1) {
> iterations = atol(argv[1]);
> }
>
> printf("Going %ld iterations\n", iterations);
> fflush(stdout);
> test_c(iterations);
> printf("* Done\n");
>
> return 0;
> }
> --- c_test.c ---
> --- struct_test_psyco.py ---
*snip*
> if __name__ == '__main__':
> from sys import argv, stdout
> if len(argv) > 1:
> iterations = long(argv[1])
> else:
> iterations = 100000
>
> import psyco
> for func in (make_dot, dot_x, dot_set_x, dot_y, dot_set_y, test_struct):
> psyco.bind(func)
> print 'Going %d iterations' % iterations
> stdout.flush()
> t = test_struct(iterations)
> print '* Done'
> --- struct_test_psyco.py ---
More information about the Python-list
mailing list