Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // courtesy of the incredible cliff click!
- // javac bench.java; time java -server bench;
- // 1410065408
- // 0.056u 0.012s 0:00.09 66.6% 0+0k 0+64io 1pf+0w
- // g++ -O bench.cpp; time a.out
- // 1410065408
- // 25.417u 0.012s 0:25.42 100.0% 0+0k 0+0io 0pf+0w
- // Java code:
- class B extends bench { int get() { return 1; } }
- class C extends bench { int get() { return 2; } }
- abstract public class bench {
- abstract int get();
- static final int LEN=100000;
- public static void main(String args[]) {
- bench f = new B();
- int sum=0;
- for( int i=0; i<LEN; i++ )
- sum += f.test();
- System.out.println(sum);
- }
- int test( ) {
- int sum=0;
- for( int i=0; i<LEN; i++ )
- sum += get();
- return sum;
- }
- }
- // C code:
- #include <stdio.h>
- #define LEN 100000
- struct bench {
- virtual int get() = 0;
- int test( ) {
- int sum=0;
- for( int i=0; i<LEN; i++ )
- sum += get();
- return sum;
- }
- };
- class B : public bench { int get() { return 1; } };
- class C : public bench { int get() { return 2; } };
- int main() {
- bench *f = new B();
- int sum=0;
- for( int i=0; i<LEN; i++ )
- sum += f->test();
- printf("%d\n",sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement