Luqmaan
Luqmaan

Reputation: 2060

FQL vs Graph API - Which is better for basic filtering?

This is a follow up to: How to filter male and female id in Facebook graph api

Suppose the task at hand is to find 10 female friends of the user. You can perform this with either the FQL or the Graph API (see original question).

Intuitively, I would expect FQL to be much faster because Facebook is taking care of the calculations for you. However, is this necessarily true?

Upvotes: 0

Views: 2150

Answers (1)

cpilko
cpilko

Reputation: 11852

I just ran a quick test (n>=3) using the Graph API Explorer, alternating between the API call and the FQL below.

This API call:

/me/friends?fields=name,gender

returned data from 300ms to 6223ms, avg = 1780ms.

This FQL call:

SELECT name, sex FROM user WHERE uid IN 
  (SELECT uid2 FROM friend WHERE uid1 = me()) AND sex = "male" LIMIT 10

returned data in 457ms to 8075ms, avg. 3690ms.

So the API call is about 20-30% faster than the FQL call, although the data doesn't match up, so it's really a crap shoot whether the API call will execute faster than the FQL call at any given time.

With the API call you still have to deal with filtering the results on your end to find 10 friends of the gender you're looking for. With FQL you can immediately loop through the result set and display them.

For what it's worth, if you compare an FQL call with everything from the AND on removed, so you're getting similar data to the API, that beats the API easily. Data is returned in 320 to 571 ms, avg. = 390ms.

Upvotes: 5

Related Questions