Changeset 563 for pjproject/trunk/pjsip/src/test-pjsip/uri_test.c
- Timestamp:
- Jun 28, 2006 4:46:49 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/test-pjsip/uri_test.c
r127 r563 33 33 34 34 #define POOL_SIZE 8000 35 #define LOOP_COUNT 10000 35 #if defined(PJ_DEBUG) && PJ_DEBUG!=0 36 # define LOOP_COUNT 10000 37 #else 38 # define LOOP_COUNT 40000 39 #endif 36 40 #define AVERAGE_URL_LEN 80 37 41 #define THREAD_COUNT 4 38 42 39 static pj_highprec_t parse_len, print_len, cmp_len; 40 static pj_timestamp parse_time, print_time, cmp_time; 43 static struct 44 { 45 pj_highprec_t parse_len, print_len, cmp_len; 46 pj_timestamp parse_time, print_time, cmp_time; 47 } var; 41 48 42 49 … … 687 694 /* Parse URI text. */ 688 695 pj_get_timestamp(&t1); 689 parse_len =parse_len + entry->len;696 var.parse_len = var.parse_len + entry->len; 690 697 parsed_uri = pjsip_parse_uri(pool, entry->str, entry->len, 0); 691 698 if (!parsed_uri) { … … 703 710 pj_get_timestamp(&t2); 704 711 pj_sub_timestamp(&t2, &t1); 705 pj_add_timestamp(& parse_time, &t2);712 pj_add_timestamp(&var.parse_time, &t2); 706 713 707 714 /* Create the reference URI. */ … … 721 728 s1.slen = len; 722 729 723 print_len =print_len + len;730 var.print_len = var.print_len + len; 724 731 pj_get_timestamp(&t2); 725 732 pj_sub_timestamp(&t2, &t1); 726 pj_add_timestamp(& print_time, &t2);733 pj_add_timestamp(&var.print_time, &t2); 727 734 728 735 len = pjsip_uri_print( PJSIP_URI_IN_OTHER, ref_uri, s2.ptr, PJSIP_MAX_URL_SIZE); … … 756 763 } 757 764 758 cmp_len =cmp_len + len;765 var.cmp_len = var.cmp_len + len; 759 766 pj_get_timestamp(&t2); 760 767 pj_sub_timestamp(&t2, &t1); 761 pj_add_timestamp(& cmp_time, &t2);768 pj_add_timestamp(&var.cmp_time, &t2); 762 769 763 770 /* Compare text. */ … … 786 793 } 787 794 788 int uri_test() 789 { 790 unsigned i, loop; 795 796 static int simple_uri_test(void) 797 { 798 unsigned i; 791 799 pj_pool_t *pool; 792 800 pj_status_t status; 793 pj_timestamp zero;794 pj_time_val elapsed;795 pj_highprec_t avg_parse, avg_print, avg_cmp, kbytes;796 797 zero.u32.hi = zero.u32.lo = 0;798 801 799 802 PJ_LOG(3,(THIS_FILE, " simple test")); … … 804 807 PJ_LOG(3,(THIS_FILE, " error %d when testing entry %d", 805 808 status, i)); 806 goto on_return;809 return status; 807 810 } 808 811 } 809 812 pjsip_endpt_release_pool(endpt, pool); 810 813 811 PJ_LOG(3,(THIS_FILE, " benchmarking...")); 812 parse_len = print_len = cmp_len = 0; 813 parse_time.u32.hi = parse_time.u32.lo = 0; 814 print_time.u32.hi = print_time.u32.lo = 0; 815 cmp_time.u32.hi = cmp_time.u32.lo = 0; 814 return 0; 815 } 816 817 static int uri_benchmark(unsigned *p_parse, unsigned *p_print, unsigned *p_cmp) 818 { 819 unsigned i, loop; 820 pj_pool_t *pool; 821 pj_status_t status; 822 pj_timestamp zero; 823 pj_time_val elapsed; 824 pj_highprec_t avg_parse, avg_print, avg_cmp, kbytes; 825 826 pj_memset(&var, 0, sizeof(var)); 827 828 zero.u32.hi = zero.u32.lo = 0; 829 830 var.parse_len = var.print_len = var.cmp_len = 0; 831 var.parse_time.u32.hi = var.parse_time.u32.lo = 0; 832 var.print_time.u32.hi = var.print_time.u32.lo = 0; 833 var.cmp_time.u32.hi = var.cmp_time.u32.lo = 0; 816 834 for (loop=0; loop<LOOP_COUNT; ++loop) { 817 835 pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE); … … 828 846 } 829 847 830 kbytes = parse_len;848 kbytes = var.parse_len; 831 849 pj_highprec_mod(kbytes, 1000000); 832 850 pj_highprec_div(kbytes, 100000); 833 elapsed = pj_elapsed_time(&zero, & parse_time);834 avg_parse = pj_elapsed_usec(&zero, & parse_time);851 elapsed = pj_elapsed_time(&zero, &var.parse_time); 852 avg_parse = pj_elapsed_usec(&zero, &var.parse_time); 835 853 pj_highprec_mul(avg_parse, AVERAGE_URL_LEN); 836 pj_highprec_div(avg_parse, parse_len);854 pj_highprec_div(avg_parse, var.parse_len); 837 855 avg_parse = 1000000 / avg_parse; 838 856 839 857 PJ_LOG(3,(THIS_FILE, 840 858 " %u.%u MB of urls parsed in %d.%03ds (avg=%d urls/sec)", 841 (unsigned)( parse_len/1000000), (unsigned)kbytes,859 (unsigned)(var.parse_len/1000000), (unsigned)kbytes, 842 860 elapsed.sec, elapsed.msec, 843 861 (unsigned)avg_parse)); 844 862 845 kbytes = print_len; 863 *p_parse = (unsigned)avg_parse; 864 865 kbytes = var.print_len; 846 866 pj_highprec_mod(kbytes, 1000000); 847 867 pj_highprec_div(kbytes, 100000); 848 elapsed = pj_elapsed_time(&zero, & print_time);849 avg_print = pj_elapsed_usec(&zero, & print_time);868 elapsed = pj_elapsed_time(&zero, &var.print_time); 869 avg_print = pj_elapsed_usec(&zero, &var.print_time); 850 870 pj_highprec_mul(avg_print, AVERAGE_URL_LEN); 851 pj_highprec_div(avg_print, parse_len);871 pj_highprec_div(avg_print, var.parse_len); 852 872 avg_print = 1000000 / avg_print; 853 873 854 874 PJ_LOG(3,(THIS_FILE, 855 875 " %u.%u MB of urls printed in %d.%03ds (avg=%d urls/sec)", 856 (unsigned)( print_len/1000000), (unsigned)kbytes,876 (unsigned)(var.print_len/1000000), (unsigned)kbytes, 857 877 elapsed.sec, elapsed.msec, 858 878 (unsigned)avg_print)); 859 879 860 kbytes = cmp_len; 880 *p_print = (unsigned)avg_print; 881 882 kbytes = var.cmp_len; 861 883 pj_highprec_mod(kbytes, 1000000); 862 884 pj_highprec_div(kbytes, 100000); 863 elapsed = pj_elapsed_time(&zero, & cmp_time);864 avg_cmp = pj_elapsed_usec(&zero, & cmp_time);885 elapsed = pj_elapsed_time(&zero, &var.cmp_time); 886 avg_cmp = pj_elapsed_usec(&zero, &var.cmp_time); 865 887 pj_highprec_mul(avg_cmp, AVERAGE_URL_LEN); 866 pj_highprec_div(avg_cmp, cmp_len);888 pj_highprec_div(avg_cmp, var.cmp_len); 867 889 avg_cmp = 1000000 / avg_cmp; 868 890 869 891 PJ_LOG(3,(THIS_FILE, 870 892 " %u.%u MB of urls compared in %d.%03ds (avg=%d urls/sec)", 871 (unsigned)( cmp_len/1000000), (unsigned)kbytes,893 (unsigned)(var.cmp_len/1000000), (unsigned)kbytes, 872 894 elapsed.sec, elapsed.msec, 873 895 (unsigned)avg_cmp)); 874 896 875 PJ_LOG(3,(THIS_FILE, " multithreaded test")); 876 897 *p_cmp = (unsigned)avg_cmp; 877 898 878 899 on_return: … … 880 901 } 881 902 903 904 /*****************************************************************************/ 905 906 int uri_test(void) 907 { 908 enum { COUNT = 4, DETECT=0, PARSE=1, PRINT=2 }; 909 struct { 910 unsigned parse; 911 unsigned print; 912 unsigned cmp; 913 } run[COUNT]; 914 unsigned i, max, avg_len; 915 char desc[200]; 916 pj_status_t status; 917 918 status = simple_uri_test(); 919 if (status != PJ_SUCCESS) 920 return status; 921 922 for (i=0; i<COUNT; ++i) { 923 PJ_LOG(3,(THIS_FILE, " benchmarking (%d of %d)...", i+1, COUNT)); 924 status = uri_benchmark(&run[i].parse, &run[i].print, &run[i].cmp); 925 if (status != PJ_SUCCESS) 926 return status; 927 } 928 929 /* Calculate average URI length */ 930 for (i=0, avg_len=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) { 931 avg_len += uri_test_array[i].len; 932 } 933 avg_len /= PJ_ARRAY_SIZE(uri_test_array); 934 935 936 /* 937 * Print maximum parse/sec 938 */ 939 for (i=0, max=0; i<COUNT; ++i) 940 if (run[i].parse > max) max = run[i].parse; 941 942 PJ_LOG(3,("", " Maximum URI parse/sec=%u", max)); 943 944 pj_ansi_sprintf(desc, "Number of SIP/TEL URIs that can be <B>parsed</B> with " 945 "<tt>pjsip_parse_uri()</tt> per second " 946 "(tested with %d URI set, with average length of " 947 "%d chars)", 948 PJ_ARRAY_SIZE(uri_test_array), avg_len); 949 950 report_ival("uri-parse-per-sec", max, "URI/sec", desc); 951 952 /* URI parsing bandwidth */ 953 report_ival("uri-parse-bandwidth-mb", avg_len*max/1000000, "MB/sec", 954 "URI parsing bandwidth in megabytes (number of megabytes " 955 "worth of URI that can be parsed per second)"); 956 957 958 /* Print maximum print/sec */ 959 for (i=0, max=0; i<COUNT; ++i) 960 if (run[i].print > max) max = run[i].print; 961 962 PJ_LOG(3,("", " Maximum URI print/sec=%u", max)); 963 964 pj_ansi_sprintf(desc, "Number of SIP/TEL URIs that can be <B>printed</B> with " 965 "<tt>pjsip_uri_print()</tt> per second " 966 "(tested with %d URI set, with average length of " 967 "%d chars)", 968 PJ_ARRAY_SIZE(uri_test_array), avg_len); 969 970 report_ival("uri-print-per-sec", max, "URI/sec", desc); 971 972 /* Print maximum detect/sec */ 973 for (i=0, max=0; i<COUNT; ++i) 974 if (run[i].cmp > max) max = run[i].cmp; 975 976 PJ_LOG(3,("", " Maximum URI comparison/sec=%u", max)); 977 978 pj_ansi_sprintf(desc, "Number of SIP/TEL URIs that can be <B>compared</B> with " 979 "<tt>pjsip_uri_cmp()</tt> per second " 980 "(tested with %d URI set, with average length of " 981 "%d chars)", 982 PJ_ARRAY_SIZE(uri_test_array), avg_len); 983 984 report_ival("uri-cmp-per-sec", max, "URI/sec", desc); 985 986 return PJ_SUCCESS; 987 } 988
Note: See TracChangeset
for help on using the changeset viewer.