`stdLambda` performance re-visited

Đang mở
#49 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
visualbasic
Lĩnh vực
performance

Hướng nghiên cứu

The issue provides a VBA benchmark comparing stdLambda with clsMathParser, but names no source files or tests. Start by reproducing the supplied benchmark and reading the stdLambda implementation and commit 2a9b2e0. Done is not defined; the issue suggests investigating a pre-populated stack and other performance differences without selecting a concrete change.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

lib-stdLambda megathread performance

stdLambda Performance

It has come to my attention that there exists another library a lot like stdLambda, named clsMathParser. This library apparently existed since 2004(?!), so totally unsure how this skipped passed my radar! It's not a very intuitive library but essentially functions as follows:

With new clsMathParser
  .storeExpression("x+1")
  For i = 1 to 100
    variable("x") = i
    Debug.Print .eval()
  next
End With

This library is, according to my testing, 5x vaster than stdLambda. Test set:

Sub test()
  Dim math As New clsMathParser
  Dim lambda As stdLambda: Set lambda = stdLambda.Create("$1^2+$1+2")
  
  If math.StoreExpression("x^2+x+2") Then
    With stdPerformance.Measure("clsMathParser", 10000)
      Dim i As Double, l As Double
      For i = 1 To 1000000
        math.variable("x") = i / 1000
        l = math.Eval()
      Next
    End With
    
    With stdPerformance.Measure("stdLambda", 10000)
      For i = 1 To 1000000
        l = lambda.Run(i / 1000)
      Next
    End With
  End If
End Sub

Comparrison of algorithm

  • clsMathParser's stack is pre-populated with values paired with operators. This ultimately means less operations done in VBA side:
    • clsMathParser splits x^2+x+2 into 3 operations:
      • ET(0) = completion op
      • ET(1) = ^ prevArg + varX^2 (???)
      • ET(2) = + prevArg + varX
      • ET(3) = + 0+2
    • stdLambda splits$1^2+$1+2 into 7 operations
      • ops(0) = Arg 1
      • ops(1) = Push 2
      • ops(2) = Op Pow
      • ops(3) = Arg 1
      • ops(4) = Op Add
      • ops(5) = Push 2
      • ops(6) = Op Add
      • ops(7) = Completion
  • stdLambda's starts with an empty stack and alocates it with values at runtime. Though we're only copying a few bytes I guess this consumes a lot of time compared to having all that data pre-prepared. A pre-populated stack is something we should likely look into.
  • stdLambda used to be copying argument location from a string at runtime, which is slow! I changed this and it saves some 30µs per operation. Fixed in 2a9b2e0
  • clsMathParser isn't stand alone sadly, and doesn't provide object access. stdLambda does provide object access and is standalone by comparrison (although technically requires stdICallable - easily removed by comparrison)
  • Cleverly clsMathParser uses a ByRef param for the return type. That shaves off some time, although not significant in my tests. But still clever fosho :)
Ngôn ngữ chính
VBA
Star
412
Fork
70
Merge trung bình
17 giờ 22 phút
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sancarn/stdVBA

Tất cả issue của sancarn/stdVBA

Issue tương tự

Thêm issue về Performance

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.