在VB中,我们经常要处理字符串列表,为图方便,有人喜欢用Collection来寄存字串列表,引用时再使用Collection.Item(Index)读取。Collection确实很方便,但Collection的读取效率极低,需要频繁调用的数据最好不要用Collection寄存,改用数组,效果会好几亿倍。不信你自己测试一下

测试代码:

Private Sub Form_Load()

    Dim t As Double, i As Long, t1 As Double, t2 As Double

    t = Timer

    For i = 1 To 10000

        col.Add "StringTest"

    Next

    t1 = Timer - t

    t = Timer

    For i = 1 To 10000

        ReDim Preserve SA(i - 1)

        SA(i - 1) = "StringTest"

    Next

    t2 = Timer - t

    Debug.Print "Load", t1, t2, t1 / t2

   

End Sub

 

Private Sub引用_Click()

    Dim i As Long, s As String

    Dim t As Double, t1 As Double, t2 As Double

    t = Timer

    For i = 1 To col.Count

        s = col.Item(i)

    Next

    t1 = Timer - t

    t = Timer

    For i = LBound(SA) To UBound(SA)

        s = SA(i)

    Next

    t2 = Timer - t

    Debug.Print "引用", t1, t2, t1 / t2

End Sub

Private Sub Load2_Click()

    Dim t As Double, i As Long, t1 As Double, t2 As Double

    Set col = Nothing

    t = Timer

    For i = 1 To 10000

        col.Add "StringTest"

    Next

    t1 = Timer - t

    t = Timer

    ReDim SA(10000 - 1)

    For i = 1 To 10000

        SA(i - 1) = "StringTest"

    Next

    t2 = Timer - t

    Debug.Print "Load2", t1, t2, t1 / t2

End Sub

 

下图是我的测试结果:

 

看看第三行第三个数据就知道差别了!!!

posted @ 2012-02-02 21:06 kason 阅读(8) 评论(0) 编辑

/*
  图片验证码 Powered By KASON
  转载请注明出处:http://www.cnblogs.com/kason/
 */


  session_start();
  $num=4;//验证码个数
  $width=80;//验证码宽度
  $height=20;//验证码高度
  $code=' ';
  for($i=0;$i<$num;$i++)//生成验证码
  {
   switch(rand(0,2))
   {
    case 0:$code[$i]=chr(rand(48,57));break;//数字
    case 1:$code[$i]=chr(rand(65,90));break;//大写字母
    case 2:$code[$i]=chr(rand(97,122));break;//小写字母
   }
  }
  $_SESSION["VerifyCode"]=$code;
  $image=imagecreate($width,$height);
  imagecolorallocate($image,255,255,255);
  for($i=0;$i<80;$i++)//生成干扰像素
  {
   $dis_color=imagecolorallocate($image,rand(0,2555),rand(0,255),rand(0,255));
   imagesetpixel($image,rand(1,$width),rand(1,$height),$dis_color);
  }
  for($i=0;$i<$num;$i++)//打印字符到图像
  {
   $char_color=imagecolorallocate($image,rand(0,2555),rand(0,255),rand(0,255));
   imagechar($image,60,($width/$num)*$i,rand(0,5),$code[$i],$char_color);
  }
  header("Content-type:image/png");
  imagepng($image);//输出图像到浏览器
  imagedestroy($image);//释放资源

下载完整源码

posted @ 2012-02-01 13:14 kason 阅读(199) 评论(0) 编辑