This is a creation in Article, where the information may have evolved or changed.
Lenovo notebook Inter I7,2.4ghz,16g,win10
C language (should be full c,vs2015 compilation)
#include <stdio.h> #include <stdlib.h> #include <time.h>bool ishuiwen (int n) { int sn = 0; sn = n; int tn = 0; while (sn != 0) { tn = tn * 10 + sn % 10; sn = sn / 10; } if (tn == n) return true; return false;} INT&NBSP;HW1 () { int tx = 0; int x = 0; for (x = 0; x <= 10000000; x++) { if (Ishuiwen (x) == true) &NBSP;&NBsp; tx ++; } &NBSP;&NBSP;&NBSP;RETURN&NBSP;TX;} VOID&NBSP;RUNHW () { clock_t start, finish; double duration; start = clock (); int total &NBSP;=&NBSP;HW1 (); finish = clock (); duration = (double) (Finish - start) / clocks_per_sec; printf ("Total = %d, %f seconds\n ", total, duration);}
1100 MS +
---------------------------
Go 1.5.1
FUNC&NBSP;HW (Num int) bool { var source int = num var tnum int = 0 for num != 0 { tnum = tnum*10 + num%10 num = num / 10 } if tnum == source { //fmt . Println (source) return true } &NBSP;&NBSP;&NBSP;RETURN&NBSP;FALSE}FUNC&NBSP;HW () { all := 10000000 t1 := time. Now () total := 0 for n := 0; n <= all; n++ { if HW (n) { total++ } } t2 := time. Now () fmt. Println (total) fmt. Println (T2. Sub (t1))}
200 ms +
----------------
Rust 1.2
Use time::*; Fn main () { hw21 ();} Fn hw21 () { let local1 = time::now (); hw2 (); let local2 = time::now (); println! ("{:?}", local2-local1);} FN&NBSP;HW2 () { let mut tx:i32 = 0; for X&NBSP;IN&NBSP;0..10000000&NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF&NBSP;HW (x) == true { tx=tx+1; } } println! ("--{:?} --", &NBSP;TX);} FN&NBSP;HW (N:&NBSP;I32) -> bool { let mut sn:i32 = n; let mut tn:i32 = 0; while sn != 0 { tn = tn*10 + sn%10; sn = sn/10; } if tn == n { return true; } return false;}
900 MS +
-----------------
Nim 0.11.2
Import strutils, timesproc ishuiwen (n : int): &NBSP;BOOL&NBSP;=&NBSP;&NBSP;VAR&NBSP;SN : int sn = n var tn : int tn = 0 while sn != 0 : tn = tn * 10 + sn mod 10 sn = sn div 10 if tn &NBSP;==&NBSP;N&NBSP;:&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;TRUE&NBSP;&NBSP;RETURN&NBSP;FALSEPROC&NBSP;HW1 () : int = var tx:int = 0 for x in 0..10000000 : if ishuiwen (x) == true : tx=tx+1 return txvar t0 = times.cputime () var total : &NBSP;INT&NBSP;=&NBSP;HW1 () Var t1 = times.cputime () echo ("nim hw all ok ", total, " . use : ", t1 - t0)
4000 MS +
I'm not trying to say who's good or bad!!
I'm not a language supporter. Need to keep improving anyway!