The speed of OpenFHE and Seal libraries

Hi, everyone!
I write a project to calculate the exp function with seal and openfhe. but the cost is so different. I want to know the reason.

Fast exponentiation time: 0 milliseconds
Native exponentiation time: 69172 milliseconds
18

    [  1,1949600325,3264722,240353875,  0, ...,  0,  0,  0,  0,  0 ]
    [  0,  0,  0,  0,  0, ...,  0,  0,  0,  0,  0 ]
2.72281e+280
Native exponentiation time: 2802 milliseconds
( 1 2 3 4 5 6 7 8 9 10 ... )
( 1 1949600325 3264722 240353875 -1946383819 1588584024 2012428798 -329404789 903471762 1887600081 ... )

openfhe only cost 2802 ms. i want to know the reason. thanky you。

Can you provide further details on the crypto-parameters you used, including the polynomial approximation algorithm, range, and polynomial degree?

To ensure a fair comparison, make sure you use the same (or very similar) cryptographic parameters in both libraries, particularly the ring dimension and ciphertext coefficient modulus.

Of course!
I did not use the polynomial approximation algorithm. I used the fast exp algo with BGV.
this is SEAL:

EncryptionParameters parms(scheme_type::bgv);
    size_t poly_modulus_degree = 32768;
    parms.set_poly_modulus_degree(poly_modulus_degree);
    parms.set_coeff_modulus(CoeffModulus::BFVDefault(poly_modulus_degree));
    parms.set_plain_modulus(PlainModulus::Batching(poly_modulus_degree, 32));

this is openfhe:

CCParams<CryptoContextBGVRNS> params;
    params.SetSecurityLevel(HEStd_NotSet);
    params.SetRingDim(32768);
    params.SetMultiplicativeDepth(16);
    params.SetPlaintextModulus(4293918721);//32bit

I already check the parameters. Both have the same ring dimension and Plaintext modulus. (emmm, I set the same ring dimension .The coefficient modulus may be different?)

The major difference I foresee behind the performance gap might be the Key Switching (HKS) algorithm used. OpenFHE uses the Hybrid Key-Switching (HKS) algorithm by default, whereas SEAL uses the Brakerski-Vaikuntanathan (BV) key-switching. HKS switching is proven to be more efficient at large multiplicative depths (See this for reference).

However, several other factors could also contribute. These are entirely different implementations with different software architectures, making the root cause potentially difficult to pinpoint.

On a related note, were you using memory pools with SEAL?

OK, thank you。
I don’t use the memory pool actually. I will try to use it. Then I also want to know that may be The default setting of OpenFHE enables multi-threading(compare to seal). is that right? thank you so much.

Correct, OpenFHE supports multi-threading (via OpenMP) by default, unless you are building for
EMSCRIPTEN. I think SEAL has it disabled by default.

Thank you!!!
I have another question, I just set the parameters as simply as below, will it use HKS? Doesn’t HKS require a special modulus to use? In what situations does OpenFHE use HKS?

 Step1:set the params
    CCParams<CryptoContextBGVRNS> params;
    params.SetSecurityLevel(HEStd_NotSet);
    params.SetRingDim(32768);
    params.SetMultiplicativeDepth(16);
    params.SetPlaintextModulus(4293918721); 

It is used by default for most of the schemes. HKS is recommended for large-multiplicative-depth computations like your case. You can set it as follows:
parameters.SetKeySwitchTechnique(HYBRID)

In low-multiplicative-depth (< 5), the BV method might be more efficient.

Check the OpenFHE parameters manual to learn more about it.

You can always print out the parameters after initializing the crypto-context, and you will know for sure which Key-Switching technique is being used.